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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greg.1.anderson’s picture

Status: Active » Fixed

Sorry, the rsync help is not super-clear.

$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',
      'delete' => TRUE,
    ),
  ),
);
MXT’s picture

Yeah it works!

Thank you

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Elijah Lynn’s picture

Can 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

greg.1.anderson’s picture

For 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'.

Elijah Lynn’s picture

You sir, are awesome!!!!

Thanks very much for this verbose Drush lesson.

Elijah

RowboTony’s picture

Status: Closed (fixed) » Active

Hi, 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

greg.1.anderson’s picture

Status: Active » Fixed

Drush 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, whereas drush 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, and drush core-rsync --delete ... will pass the --delete option to rsync.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

JSCSJSCS’s picture

Status: Fixed » Active

I 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

 'command-specific' => array (
    'sql-dump' => array (
    'result-file' => '/home/user/sqldumps/sqldump.sql',
    'gzip' => TRUE,
    ),
    'rsync' => array (
      'RSYNC-FLAG' => '--delete',
      'mode' => 'rultvz',  //instead of adding '--mode=rultvz' in drush rsync command
    ),
  ),

If I use the Command Line, RSYNC-FLAG it works as expected and deletes destination files no longer on the remote:

$ drush rsync @mdjprod:%files @mdjdev:%files --RSYNC-FLAG --delete-after --dry-run
You will destroy data from /cygdrive/c/wamp/www/example.com/sites/default/files and replace with data from user@okul.dreamhost.com:/home/user/example.com/sites/default/files/
Do you really want to continue? (y/n): y
receiving file list ... done
./
deleting testrsync.txt

sent 127 bytes  received 8861 bytes  5992.00 bytes/sec
total size is 404030639  speedup is 44952.23 (DRY RUN)

so something is not working correctly with the alias.drushrc.php file for me.

I also tried

      'RSYNC-FLAG' => 'delete',  //remoded the '--'

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.

greg.1.anderson’s picture

Status: Closed (fixed) » Fixed

RSYNC-FLAG means that you should simply place your rsync flag in as an option to Drush. Try this:

 'command-specific' => array (
    'sql-dump' => array (
    'result-file' => '/home/user/sqldumps/sqldump.sql',
    'gzip' => TRUE,
    ),
    'rsync' => array (
      'delete' => TRUE,
      'mode' => 'rultvz',  //instead of adding '--mode=rultvz' in drush rsync command
    ),
  ),

Didn't test it, but I believe that works.

JSCSJSCS’s picture

Status: Active » Fixed

Wow, 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.

greg.1.anderson’s picture

Version: 7.x-4.4 » 8.x-6.x-dev
Status: Fixed » Active

#2 says that works. Have you tried on the latest version of Drush, perhaps?

JSCSJSCS’s picture

Yes, I am on Drush 5.8 and that might be part of the problem as #2 was working two years ago.

greg.1.anderson’s picture

Assigned: Unassigned » greg.1.anderson
Category: support » bug

Okay, I'll take a look.

greg.1.anderson’s picture

Title: How to pass "--delete" option to rsync ? » Fix options defined in config files without values for "strict options" commands (e.g. "--delete" option to rsync)
Status: Active » Needs review
FileSize
2.05 KB

This should do the trick. I'll just commit this in a couple of days if no one has any comments.

JSCSJSCS’s picture

Thanks 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.

greg.1.anderson’s picture

Status: Needs review » Needs work

Thanks 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.

JSCSJSCS’s picture

Okay, will do, but what files control what the "drush help command" show?

JSCSJSCS’s picture

I 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.

greg.1.anderson’s picture

Did you make #20 on Drush 8.x-6.x? It did not apply for me.

JSCSJSCS’s picture

No, I made it on the 7.x-5.x branch.

JSCSJSCS’s picture

I 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.

greg.1.anderson’s picture

New development is done on 8.x-6.x.

JSCSJSCS’s picture

I 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?

greg.1.anderson’s picture

On 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.

JSCSJSCS’s picture

I don't mind doing it, I just did not know how it all worked.

JSCSJSCS’s picture

Here 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!

greg.1.anderson’s picture

Status: Needs work » Fixed

Committed. Thanks for all of your work on this issue.

greg.1.anderson’s picture

Version: 8.x-6.x-dev » 7.x-5.x-dev
Status: Fixed » Patch (to be ported)

This 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)?

JSCSJSCS’s picture

Yes, #23 applies cleanly to 7.x-5.x for me.

greg.1.anderson’s picture

Status: Patch (to be ported) » Fixed

Committed #23 to 7.x-5.x branch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.