Currently, drush passes the arguments --single-transaction --opt -Q when using the drush sql dump command to run mysqldump. Some users might find that they want to change the arguments. For instance, those that keep their database dumps under version control would find that skipping the extended inserts would be much better and make their diffs smaller and more VCS friendly. (This does, however, increase the size of the dumps, e.g., 35 MB to 46 MB, but the VCS repository savings vastly outweighs this.) The below patch allows users to configure their drushrc.php to change the arguments but still defaults to the standard --single-transaction --opt -Q arguments.

I tried it out myself a few times and it works well. Here it is with no drushrc.php, that is, the default arguments are used:

exampledotcom@server1:~/web$ drush sql dump --uri=http://example.com > newdump.sql &

exampledotcom@server1:~$ ps aux | grep mysqldump
1002     16789  0.0  0.0   1784   544 pts/4    R+   19:41   0:00 grep mysqldump
exampledotcom@server1:~$ ps aux | grep mysqldump
1002     16816  0.0  0.0   1772   480 pts/2    S+   19:42   0:00 sh -c mysqldump --single-transaction --opt -Q -hserver2.example.com -uusername -p*************** databasename 
1002     16817  5.0  0.2   5624  1768 pts/2    R+   19:42   0:00 mysqldump --single-transaction --opt -Q -hserver2.example.com -uusername -px xxxxxxxxxxxxx databasename
1002     16819  0.0  0.0   1784   548 pts/4    S+   19:42   0:00 grep mysqldump
exampledotcom@server1:~$

And once I've copied the example.drushrc.php to drushrc.php and change the mysqldump-arguments configuration, here's how it runs:

exampledotcom@server1:~/web$ drush sql dump --uri=http://example.com > newdump2.sql &

exampledotcom@server1:~$ ps aux | grep mysqldump1002     17188  0.0  0.0   1772   480 pts/2    S+   19:55   0:00 sh -c mysqldump --single-transaction --opt -Q --skip-extended-insert -hserver2.example.com -uusername -p*************** databasename 
1002     17189 14.0  0.2   5680  1744 pts/2    R+   19:55   0:00 mysqldump --single-transaction --opt -Q --skip-extended-insert -hserver2.example.com -uusername -px xxxxxxxxxxxxx databasename
1002     17191  0.0  0.0   1784   548 pts/4    S+   19:55   0:00 grep mysqldump
exampledotcom@server1:~$

Now dumps can be SVN/git friendly or in any other format. Plus users can use multiple drushrc.phps to have various SQL dump formats set as presets.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rsvelko’s picture

Status: Needs review » Reviewed & tested by the community

Here is the review:

the patch has 3 chunks:
1. wholy commented out block in example.drushrc.php with thorough explanations. It is in the right spot of the file.

2. again in the right spot of sql.drush.inc (after the ommit tables stuff - like in 1.) there is a new var holding the options and ensuring that if nothing given from drushrc the defaults will hold

+

+ // Pass the necessary arguments from drushrc.php. If there are no arguments,

+ // use the default --single-transaction --opt -Q

+ $mysqldump_arguments = drush_get_option('mysqldump-arguments');

+ if (!$mysqldump_arguments) {

+ $mysqldump_arguments = '--single-transaction --opt -Q';

+ }

+

3. the actual usage of the option string -

- $extra = ' --single-transaction --opt -Q' . _drush_sql_get_credentials($db_spec);
+ $extra = ' ' . $mysqldump_arguments . _drush_sql_get_credentials($db_spec);

patch is ok - lets commit it .

PS. God bless the user "sun" for the dreditor greasemonkey helper - especially the hide/show buttons - with which I reviewed this patch.

rsvelko’s picture

Title: Allow Users To Set myqldump Arguments In drushrc.php » Allow Users To Set myqldump Arguments In drushrc.php (for drush sql dump)

here is the sql cli patch that pends:
http://drupal.org/node/570890

rsvelko’s picture

Status: Reviewed & tested by the community » Needs work

actually I would like to slightly change the last patch and incorporate the sql cli stuff in in too.

This is going to be called - the "sql options override patch"

rsvelko’s picture

Status: Needs work » Needs review
Issue tags: +sql additional arguments patch
FileSize
5.17 KB

please review this

moshe weitzman’s picture

Waiting for #460924: Remote site aliases for Drush (Proposal and implementation) to land before messing with related code. Should happen soon. We should be able to get this in easily before next release.

Brian@brianpuccio.net’s picture

Hey rsvelko, thanks for jumping in, I was away for a while. I appreciate it.

moshe weitzman’s picture

perhaps greg has an opinion here.

greg.1.anderson’s picture

Status: Needs review » Needs work

Yep. I'll comment when I have more time, but I think this will need some modification to play nice with #671906: mysql credentials leak in drush sqlc.

greg.1.anderson’s picture

Okay, I took a look at this today. I don't think there's any reason to tie this issue to #671906: mysql credentials leak in drush sqlc any more.

I don't think there is any value to grouping these options in a multi-dimensional array. I would instead recommend something like this:

# $options['mysql-cli'] = '-A';
# $options['mysql-query'] = '';
# $options['mysql-dump'] = '--single-transaction --opt -Q'
# // To create VCS/diff friendly dumps:
# $options['mysql-dump'] = '--single-transaction --opt -Q --skip-extended-insert '

Did I get the args right for mysql dump?

Anyway, this would allow people to use the slower VCS/diff-friendly dumps on sql-dump, and use faster unordered dumps for sql-sync:

$options['command-specific']['sql-dump'] = array( 'mysql-dump' => '...' );

(n.b. 'sql-dump' would be 'sql dump' prior to completion of #550522: Change white spaces in commands by another symbol.)

The other advantage of going this way is that you can then make the code read more like this:

$command .= drush_get_option('mysql-cli', '-A') . ' ' . _drush_sql_get_credentials();

Extra spaces do not hurt exec, so put the spaces in the code -- do not require them in the options.

rsvelko’s picture

My last #4 patch's idea was to give the max flexibility. I no longer remember its anatomy and so - have fun and do what you please with my patch code. Hope it helps.

greg.1.anderson’s picture

Yes, it helps.

Anyway, I'll put this back on my plate for later processing, unless Brian comes back around and picks it up.

greg.1.anderson’s picture

Bump... will try to get this in for the next release, but I imagine that is optional.

greg.1.anderson’s picture

Issue tags: +drush-3.0

Tag for drush-3.0

greg.1.anderson’s picture

Just a note that while I think this issue should be done eventually,, the needs of the O.P. are already met by the existing flag --ordered-dump, so I've been doing more important things and probably won't get to this until sometime after #759906: Update core without moving core files out of the way..

colan’s picture

Component: Code » SQL

Subscribing.

greg.1.anderson’s picture

moshe weitzman’s picture

SolomonGifford’s picture

The use case in #17 assumes a unique --where is sent on each table (implying a separate mysqldump command for each partial table). This would make a single command line solution quite complex.

greg.1.anderson’s picture

We should convert the drush sql-dump command to use strict options (Drush 6 only); this would allow multiple 'where' options to be used at the same time, just like mysql dump. However, I must acknowledge that this is still not as good of a solution as #1672894, as it is difficult to represent multiple 'where' conditions in an alias record this way. Perhaps we should be having this discussion in the other incident.

greg.1.anderson’s picture

Version: » 8.x-6.x-dev
Status: Needs work » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If this feature is still desired, you may copy it to our Github project. For best results, create a Pull Request that has been updated for the master branch. Post a link here to the PR, and please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.

moshe weitzman’s picture

Status: Closed (won't fix) » Closed (duplicate)
Issue tags: -Needs migration