#1471254: drush rsync's "--simulate" fails, reports as "unknown option" was submitted and closed since the simulate option now needs to be specified before the rsync command. However, using the 'command-option' in an alias to define the simulate option for the rsync command now breaks. This approach is described in #854722-3: Protecting a site from having it's database overwritten.. How can we accomplish this functionality with Drush 5.x?

My @prod alias (see attached for both aliases):

$aliases['prod'] = array(
  'uri' => 'www.test.org',
  'root' => '/home/testorg/domains/www.test.org',
  'remote-host' => 'test.org',
  'remote-user' => 'testorg',
  'path-aliases' => array(
    '%files' => 'sites/default/files',
    '%dump' => '/home/testorg/tmp/sql-sync-prod.sql',
  ),
  'command-specific' => array (
    'sql-sync' => array (
      'simulate' => '1',
    ),
    'rsync' => array (
      'simulate' => '1',
    ),
  ),
);

Snippet of output from drush (see attached for full commands and output):

Calling system(rsync -e 'ssh ' -rlptDzv --exclude=".git" --exclude=".gitignore" --exclude=".hg" --exclude=".hgignore" --exclude=".hgrags" --exclude=".bzr" --exclude=".bzrignore" --exclude=".bzrtags" --exclude=".svn" --stats --progress --simulate=1 testorg@test.org:/home/testorg/domains/www.test.org/sites/default/files/ /srv/www/sites/default/files);
rsync: --simulate=1: unknown option
rsync error: syntax or usage error (code 1) at main.c(1443) [client=3.0.7]
Could not rsync from testorg@test.org:/home/testorg/domains/www.test.org/sites/default/files/ to /srv/www/sites/default/files [2.64   [error]
sec, 9.03 MB]
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greg.1.anderson’s picture

I think that the best option for protecting a site from sql-sync would be to use a policy file.

Using global options with command specific is, however, broken; even if --simulate is not the best way to protect a site, it should still be valid to put global options in command-specific records for commands such as rsync that use strict option handling, so this bug should be addressed.

greg.1.anderson’s picture

Category: support » bug
Status: Active » Needs review
FileSize
2 KB

Here, try this patch. This allows command specific global options iff said global option is cached in a context. Unsupported global options are silently ignored. Perhaps not ideal. Maybe we should at least throw an error if !array_key_exists('context', $global_options[$key]);

dkingofpa’s picture

I applied the patch in #2 to my drush 5.1 install. That worked for my simulate flag needs with rsync. I didn't try it with any other global options.

But I like your policy suggestion better. I think I'll head down that path.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Sounds like RTBC

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed

Committed with the addition of a drush_log(..., 'warning') if someone tries to use an unsupported command-specific global option with a command that uses strict option handling.

Status: Fixed » Closed (fixed)

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