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.php
s to have various SQL dump formats set as presets.
Comment | File | Size | Author |
---|---|---|---|
#4 | drush_sql_additional_arguments.patch | 5.17 KB | rsvelko |
drush_mysqldump_arguments.patch | 2.72 KB | Brian@brianpuccio.net |
Comments
Comment #1
rsvelko CreditAttribution: rsvelko commentedHere 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.
Comment #2
rsvelko CreditAttribution: rsvelko commentedhere is the sql cli patch that pends:
http://drupal.org/node/570890
Comment #3
rsvelko CreditAttribution: rsvelko commentedactually 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"
Comment #4
rsvelko CreditAttribution: rsvelko commentedplease review this
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedWaiting 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.
Comment #6
Brian@brianpuccio.net CreditAttribution: Brian@brianpuccio.net commentedHey rsvelko, thanks for jumping in, I was away for a while. I appreciate it.
Comment #7
moshe weitzman CreditAttribution: moshe weitzman commentedperhaps greg has an opinion here.
Comment #8
greg.1.anderson CreditAttribution: greg.1.anderson commentedYep. 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.
Comment #9
greg.1.anderson CreditAttribution: greg.1.anderson commentedOkay, 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:
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:
(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:
Extra spaces do not hurt exec, so put the spaces in the code -- do not require them in the options.
Comment #10
rsvelko CreditAttribution: rsvelko commentedMy 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.
Comment #11
greg.1.anderson CreditAttribution: greg.1.anderson commentedYes, it helps.
Anyway, I'll put this back on my plate for later processing, unless Brian comes back around and picks it up.
Comment #12
greg.1.anderson CreditAttribution: greg.1.anderson commentedBump... will try to get this in for the next release, but I imagine that is optional.
Comment #13
greg.1.anderson CreditAttribution: greg.1.anderson commentedTag for drush-3.0
Comment #14
greg.1.anderson CreditAttribution: greg.1.anderson commentedJust 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..
Comment #15
colanSubscribing.
Comment #16
greg.1.anderson CreditAttribution: greg.1.anderson commentedSee also #1283978: Parameter --skip-add-locks in mysql dump and #898924: Allow users to set arguments for mysql command in sql-sync and others.
Comment #17
moshe weitzman CreditAttribution: moshe weitzman commentedAnother use case at #1672894: sql-sync support the --where condition
Comment #18
SolomonGifford CreditAttribution: SolomonGifford commentedThe 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.
Comment #19
greg.1.anderson CreditAttribution: greg.1.anderson commentedWe 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.
Comment #20
greg.1.anderson CreditAttribution: greg.1.anderson commentedThis 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.
Comment #21
moshe weitzman CreditAttribution: moshe weitzman commentedCopied to Github at https://github.com/drush-ops/drush/issues/178