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.
Hi all, I'm trying to pass the "--delete" options to rsync command (the purpose is to delete extraneous files from destinations dirs) setting that in my alias, like this:
$aliases['staging'] = array(
'remote-host' => 'myRemoteHost',
'remote-port' => 3306,
'remote-user' => 'MyUser',
'path-aliases' => array(
'%drush-script' => '/var/www/drush/drush',
'%files' => 'sites/default/files',
),
'command-specific' => array (
'sql-sync' => array (
'simulate' => '1',
),
'rsync' => array (
'simulate' => '0',
'RSYNC-FLAG' => '--delete',
),
),
);
But without success: what's wrong?
Thank to everyone wants help me
MXT
Comments
Comment #1
greg.1.anderson CreditAttribution: greg.1.anderson commentedSorry, the rsync help is not super-clear.
Comment #2
MXTYeah it works!
Thank you
Comment #4
Elijah LynnCan someone point me to documentation on what the simulate flag does? I can't find it in man rsync or drush help rsync. Maybe I am overlooking something.
Thanks
Comment #5
greg.1.anderson CreditAttribution: greg.1.anderson commentedFor global command options, see
drush topic core-global-options
. Note that the simulate option is intended to show you what the Drush command would do without actually doing it; however not all commands implement this feature correctly, so sometimes drush --simulate will go ahead and execute the command. --simulate is supported for rsync, but must appear before the rsync command name to work. All the same, I would recommend against using --simulate to 'protect' a site against rsync (as has been suggested in the past), and instead use a policy file as described in 'drush topic docs-policy'.Comment #6
Elijah LynnYou sir, are awesome!!!!
Thanks very much for this verbose Drush lesson.
Elijah
Comment #7
RowboTony CreditAttribution: RowboTony commentedHi, I've been watching this thread for a while, and all is well in my drushrc.php files. I'm wondering however - what is the syntax for using
--RSYNC-FLAG
from the command line? I'd often like to toss in some extra rsync command such as "--delete", but no matter what I try I can't get--RSYNC-FLAG
to work on the cli. I use Aegir, and here's what I'll often do to sync a site down from live to dev.drush core-rsync --exclude=drushrc.php --exclude-conf --exclude-sites @www.example.com:%site @example-dev.aegir.dev:%site -v
Where/how, could I add
--RSYNC-FLAG
in that thar command?Thank you,
--Tony
Comment #8
greg.1.anderson CreditAttribution: greg.1.anderson commentedDrush options should come before the core-rsync command, whereas rsync flags come after core-rsync. Therefore,
drush -v core-rsync ...
would put drush into verbose mode, whereasdrush core-rsync -v ...
will put rsync into verbose mode. (n.b. If Drush is in Verbose mode, it will also pass a --verbose to rsync; the preceding example is for illustrative purposes.)Edit:
To be explicit, then,
drush --delete core-rsync ...
is a syntax error, anddrush core-rsync --delete ...
will pass the --delete option to rsync.Comment #10
JSCSJSCS CreditAttribution: JSCSJSCS commentedI would like to add that I am unable to pass an RSYNC-FLAG through with aliases on Windows. I don;t think it is a windows issue.
If I use #1 suggestion I do not get an error, but destination files are not deleted
add to
If I use the Command Line, RSYNC-FLAG it works as expected and deletes destination files no longer on the remote:
so something is not working correctly with the alias.drushrc.php file for me.
I also tried
to make it similar to the mode command that does not add the "--" to the front of the options, but that does not work ether.
Edit:
I should add that when I run the drush with -s and review the comand that is being generated, if I add the --RSYNC-FLAG --delete-after to the command line, the the command includes --delete after, but if i use #1 or variants of it, there is nothing added to the command being created.
Comment #11
greg.1.anderson CreditAttribution: greg.1.anderson commentedRSYNC-FLAG means that you should simply place your rsync flag in as an option to Drush. Try this:
Didn't test it, but I believe that works.
Comment #12
JSCSJSCS CreditAttribution: JSCSJSCS commentedWow, thanks for the quick reply. I had tried that before.
That suggestion adds "--delete=1" to the generated command and invokes an error that says:
rsync: --delete=1: option does not take an argument
rsync error: syntax or usage error (code 1) at main.c(1435) [client=3.0.8]
I tried
'delete' => '',
also
no joy.
Comment #13
greg.1.anderson CreditAttribution: greg.1.anderson commented#2 says that works. Have you tried on the latest version of Drush, perhaps?
Comment #14
JSCSJSCS CreditAttribution: JSCSJSCS commentedYes, I am on Drush 5.8 and that might be part of the problem as #2 was working two years ago.
Comment #15
greg.1.anderson CreditAttribution: greg.1.anderson commentedOkay, I'll take a look.
Comment #16
greg.1.anderson CreditAttribution: greg.1.anderson commentedThis should do the trick. I'll just commit this in a couple of days if no one has any comments.
Comment #17
JSCSJSCS CreditAttribution: JSCSJSCS commentedThanks Greg! I wish I knew PHP better and could help out more, but I CAN write some help text for inclusion with the documentation.
I believe that you have covered almost all the ways to pass rsync commands directly, and I have discovered (learned) the ways to do it that are not explicitly allowed (i.e. cannot have multiple --filter or --exclude $KEY's).
I am suggesting that Drush remove all mention of the RSYNC-FLAG option, since it did not work and its intended use is now covered in your original (and include in this) patch.
I won't be able to test for EVERY possibility, but I think this is a good start and I did test all the possibilities outlined in the proposed documentation changes with the "drush -s" parameter to make sure they are passed through correctly.
Comment #18
greg.1.anderson CreditAttribution: greg.1.anderson commentedThanks for the documentation updates -- looks great. Some comments.
- 'RSYNC-FLAG' => 'Most rsync flags passed to drush sync will be passed on to rsync. See rsync documentation.',
Okay, this has proven to be confusing; let's just take it out, as yo suggest. Maybe you could make some examples showing 'mode' and 'delete' in the rsync command record, so that it shows up in
drush help rsync
? The docs you put in the example alias files are also good, but it would be nice to have this info in both places.multi-letter rsync options without parameters
'parameters' should be 'values'.
cannot add multiple options of same $KEY
Use 'key' in documentation.
Comment #19
JSCSJSCS CreditAttribution: JSCSJSCS commentedOkay, will do, but what files control what the "drush help command" show?
Comment #20
JSCSJSCS CreditAttribution: JSCSJSCS commentedI think I misunderstood what you were asking for. Try this patch. I added another example to the drush rsync help and added some expaination of how to pass through rsync options and values.
I also changed the wording in the examples to add "alias" where appropriate. That confused me when I first started using drush.
Comment #21
greg.1.anderson CreditAttribution: greg.1.anderson commentedDid you make #20 on Drush 8.x-6.x? It did not apply for me.
Comment #22
JSCSJSCS CreditAttribution: JSCSJSCS commentedNo, I made it on the 7.x-5.x branch.
Comment #23
JSCSJSCS CreditAttribution: JSCSJSCS commentedI could not get the patch to apply even on 7.x.5.x and I discovered that my IDE is set to delete white space at the end of lines.
Your original patch removed some trailing white space. My patch included some other changes (to .gitignore, etc.) and when I edited my patch to delete those changes, it also deleted the trailing white space changes that were in a couple of lines of the patch.
Here is the updated patch. I have tested it and it applies cleanly to the latest 7.x-5.x branch as of today.
Comment #24
greg.1.anderson CreditAttribution: greg.1.anderson commentedNew development is done on 8.x-6.x.
Comment #25
JSCSJSCS CreditAttribution: JSCSJSCS commentedI thought I was doing a bug fix (--delete was becoming --delete=1 when using drush alias comand-specific options) for 5.8.
I did not notice this original issue was on 8.x-6.x-dev. Sorry
So can I use the 8 branch in windows 7 while still on D7? If not, do you want me to open another ticket on the 7.x.5.x branch and post my patch there?
Comment #26
greg.1.anderson CreditAttribution: greg.1.anderson commentedOn drupal.org, even bug fixes are made first to the active development branch, and then backported to the stable release. If this was not done, then the new release would never be completed, as it would not be possible to keep up with the bug fixes made on the legacy branch -- an unfortunate reality in open source projects.
One issue is used for both the dev fix and the backport; don't open a new one for 7.x-5.x, as it would just be closed as a duplicate of this one.
Drush 8.x-6.x works with Drupal 6, 7 and 8. Drush 7.x-5.x works with Drupal 6 and 7. All of the Drush maintainers use the current bleeding-edge dev release of Drush as their primary tool; while you may encounter problems on the dev release (and I would not recommend pulling it daily), in general it is fairly stable. If you check out from git, it's pretty easy to switch back and forth between 8.x-6.x and 7.x-5.x.
In any event, thank you for helping out here. If you don't feel like making patches on 8.x-6.x, I will eventually circle back and pull in your changes, but it always helps to have contributions on the dev branch.
Comment #27
JSCSJSCS CreditAttribution: JSCSJSCS commentedI don't mind doing it, I just did not know how it all worked.
Comment #28
JSCSJSCS CreditAttribution: JSCSJSCS commentedHere is the new patch based on the Drush 8.x-6.x commit. I tested and it applied cleanly on this end at least.
Thanks for all the help!
Comment #29
greg.1.anderson CreditAttribution: greg.1.anderson commentedCommitted. Thanks for all of your work on this issue.
Comment #30
greg.1.anderson CreditAttribution: greg.1.anderson commentedThis could go back to 7.x-5.x now. Is #23 up to date (that is, the same as #28, but for the Drush-5 dev branch)?
Comment #31
JSCSJSCS CreditAttribution: JSCSJSCS commentedYes, #23 applies cleanly to 7.x-5.x for me.
Comment #32
greg.1.anderson CreditAttribution: greg.1.anderson commentedCommitted #23 to 7.x-5.x branch.