Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It would be nice to use the aliases.drushrc.php file alias definition to work for sql-dump, not just sql-sync.
Instead of having to add a drush @myalias sql-dump --results-file=somename.sql --gzip
We might have
'%dump-dir' => 'sqldumps',
'%dump' => 'somename.sql',
work for the sql-dump command too, so
drush @myalias sql-dump would read the aliases file and create the dump named 'somename.sql' in the "root" 'sqldumps' directory.
This could be overridden by actually using --results-file= instead of requiring its use.
Comment | File | Size | Author |
---|---|---|---|
#11 | no_gzip_confirmation-1543478-5911472.patch | 844 bytes | JSCSJSCS |
#8 | no_gzip_confirmation-1543478-5910954.patch | 841 bytes | JSCSJSCS |
#6 | no_gzip_confirmation-1543478-5908892.patch | 776 bytes | JSCSJSCS |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedYou can add command specific options to an alias. Search for command-specific' at http://api.drush.org/api/drush/examples%21example.aliases.drushrc.php/5.x (click View source)
Comment #2
JSCSJSCS CreditAttribution: JSCSJSCS commentedI was not able to find anything with the search for 'command-specific' at the link you provided, but I did find some info in the examples.alias.drushrc.php file that got me headed in the right direction. I added the follwing to my aliases.drushrc.php file:
(Keep in mind I am using Drush 5.1 but have edited my sql.drush.inc file to change the ; to && for Windows to use multi-commands correctly.
But I could use just a bit more help. How to automatically answer "y" when writing over the test.sql.gz file on subsequent executions?
$ drush @mdjdev sql-dump
Database dump saved to sqldumps\test.sql.gz [success]
$ drush @mdjdev sql-dump
gzip: sqldumps\test.sql.gz already exists; do you wish to overwrite (y or n)? y (****need this to auto answer y)
Database dump saved to sqldumps\test.sql.gz [success]
Comment #3
greg.1.anderson CreditAttribution: greg.1.anderson commentedAdd
'yes' => TRUE
to your command-specific entry for sql-dump above.Comment #4
JSCSJSCS CreditAttribution: JSCSJSCS commentedThanks for the quick respones!
I changed the alias and reloaded GIT Bash
But not getting any love (Still asking for confirmation):
$ drush @nfsdev sql-dump -v
Load alias @nfsdev [notice]
Initialized Drupal 7.12 root directory at c:\wamp\www\local.example.com [notice]
Initialized Drupal site local.example.com at sites/default [notice]
Calling system(mysqldump --result-file sqldumps\example.sql --no-autocommit --single-transaction --opt -Q example --host=localhost --user=root --password= && gzip sqldumps\example.sql);
gzip: sqldumps\example.sql.gz already exists; do you wish to overwrite (y or n)?
Interesting that "drush sa does NOT list the command-specific options, even with --full --with-optional
$ drush sa @nfsdev --full --with-optional
$aliases['nfsdev'] = array (
'uri' => 'local.example.com',
'root' => 'c:\\wamp\\www\\local.example.com',
'db_url' => 'mysql://root@localhost/example',
'path-aliases' =>
array (
'%dump-dir' => 'sqldumps',
'%dump' => 'example.sql',
'%files' => 'sites/default/files',
'%drush' => 'c:/ProgramData/Propeople/Drush',
'%site' => 'sites/local.example.com/',
),
'#file' => 'c:/Users/USERNAME/.drush/aliases.drushrc.php',
);
It makes since that it is not working though, unless the code accounts for the fact that the -y is not --y as it does got --gzip and others.
Comment #5
greg.1.anderson CreditAttribution: greg.1.anderson commentedWhoops, didn't notice that it is gzip, not Drush, that is asking for the confirmation here. We could add code to Drush to remove the destination file (with or without confirmation); that would best be handled as a separate feature request ("patches welcome").
As a workaround, you could manually remove the destination file before calling Drush. I presume you need the autoconfirm because you want to call this function from a script; if that's the case, then it should be easy enough to preflight with a file delete.
Comment #6
JSCSJSCS CreditAttribution: JSCSJSCS commentedForgive me my PHP, for I am only 5 weeks into a 6 week "Beginning PHP" college extension course.
I found that Gzip has a -f flag to halt confirmation. This patch seems to work if 'yes' => TRUE. 'yes' => FALSE or not set at all. I did not do any other testing.
This is probably the second time I have ever made a patch file, so no guarantees!
Comment #7
greg.1.anderson CreditAttribution: greg.1.anderson commentedThat looks pretty good. The first thing I see is pre-existing, but should be fixed while we're here. $file should be wrapped in drush_shell_escape_arg when passed to gzip:
$exec .= "&& gzip " . drush_escape_shell_arg($file);
Also, drush_get_option('yes') should be drush_get_context('DRUSH_AFFIRMATIVE').
Beware of typos in my off-the-cuff comments. ;) Thanks for working on this.
Comment #8
JSCSJSCS CreditAttribution: JSCSJSCS commentedI don't have a clue what the suggested changes do, but I entered them and tested for 'yes' => TRUE. 'yes' => FALSE or not set at all and everything still worked!
And as a bonus, I am honing my Git Diff patch skills.
Comment #9
JSCSJSCS CreditAttribution: JSCSJSCS commentedOops hold everythign. I made a rookie mistake and was testing on my original drush not the git clone. Need to test cuz am getting errors when using new changes.
Comment #10
greg.1.anderson CreditAttribution: greg.1.anderson commented#8 is missing a closing quote prior to drush_escape_shell_arg in both occurances.
Comment #11
JSCSJSCS CreditAttribution: JSCSJSCS commentedI found that, but actually, even though you warned me about typos, your "drush_escape_shell_arg($file);" should have been "drush_escapeshellarg($file);"
Once I found that, Gzip did not like it.
$ drush @nfsdev sql-dump
gzip: illegal option -- s
usage: gzip [-acdfhlLnNrtvV19] [-S suffix] [file ...]
Database dump failed [error]
So I created a variable to hold the results of the function and that seemed to work
$escfile = drush_escapeshellarg($file);
$exec .= " && gzip -f $escfile";
Again I did all the same tests as before, and this time on the right file!
Comment #12
greg.1.anderson CreditAttribution: greg.1.anderson commentedYou misread #7; drush_escapeshellarg($file) is not quoted. The way you did it is fine, though, and all tests pass. If there are no objections, I will commit this shortly.
Comment #13
JSCSJSCS CreditAttribution: JSCSJSCS commentedIt wasn't quotes that got me, it was your extra Underscores
Thanks again!
Comment #14
greg.1.anderson CreditAttribution: greg.1.anderson commentedCommitted.