3

I understand that drush rsync is, by design, capable of preserving uid:gid.

if I am synchronizing with drush rsync @site1 @site2, and uid:did exists on both site1, and site2, all is well.

How would I go about changing the uid:gid to a specific selection on site2, within drush's command/alias config?

For example, on site1 all files are wwwrun:www, but on site2 I want to save all files as bob:admins, neither of which exists on site1.

Is there an integrated solution? I know I can use 'drush ssh @site2 "chown ..."' as a subsequent step. Can I instead define/chain the command in aliases.drush.rc?

Using "remote-user=xxx" certainly works, but, apparently, it is limited to users that are allowed SSH access on the remote box.

@ remote
egrep -i "allowusers" /usr/local/etc/ssh/sshd_config
    AllowUsers         root locuse testuser

@ local
whoami
    locuse
drush --remote-user=testuser rsync @siteA @siteB
    You will destroy data from locuse@siteB.loc:/srv/www/siteB/ and replace with data from /srv/www/siteA//
    Do you really want to continue? (y/n): y

@ remote
ls -al PROD/ | head -n 5
    total 248K
    drwsrws--- 10 testuser users 4.0K Mar  8 00:08 ./
    drwxrwx---  4 wwwrun   www   4.0K Mar  8 08:11 ../
    -rw-rw----  1 testuser users 6.5K Mar  6 17:31 authorize.php
    -rw-rw----  1 testuser users  64K Mar  6 17:31 CHANGELOG.txt
    -rw-rw----  1 testuser users  996 Mar  6 17:31 COPYRIGHT.txt

That doesn't address my particular issue/interest.

More clearly, what I want to do is ssh-in from local->remote as an authorized user ('locuse' or 'root'), but I have the remote files' uid:gid set to an existing pair, where the target uid does/will NOT have ssh-access (e.g., wwwrun:www).

Reading the output of "man rsync," I read:

USING RSYNC-DAEMON FEATURES VIA A REMOTE-SHELL CONNECTION

Then @siteB

mkdir -p            /path/to/target
chown -R wwwrun:www /path/to/target

vi /etc/rsyncd.conf
    transfer logging = true
    log format       = %h %o %f %l %b
    log file         = /var/log/rsyncd.log
    pid file         = /var/run/rsyncd.pid
    lock file        = /var/run/rsync.lock
    hosts deny       = *
    use chroot       = no
    [siteB]
        path = /path/to/target
        hosts allow = *
        comment = COMMENTS
        uid = wwwrun
        gid = www
        read only = no
        list = yes

and @local

whoami
    locuse
ls -al ~/SourceDir
    total 240K
    drwxrwxrwx  2 locuse users 4.0K Mar  8 10:42 ./
    drwxr-xr-x 27 locuse users 4.0K Mar  8 10:41 ../
    -rw-r--r--  1 locuse users 5.2K Mar  8 10:43 file1.txt
    -rw-r--r--  1 locuse users 2.8K Mar  8 10:43 file2.txt

rsync -av --rsh=ssh ~/SourceDir/ root@siteB.loc::SiteB

Checking on remote:

ls -al /path/to/target
    total 240K
    drwxrwxrwx  2 root   root 4.0K Mar  8 10:42 ./
    drwxr-xr-x 27 wwwrun www  4.0K Mar  8 10:41 ../
    -rw-r--r--  1 wwwrun www  5.2K Mar  8 10:43 file1.txt
    -rw-r--r--  1 wwwrun www  2.8K Mar  8 10:43 file2.txt

It ends up with exactly the end-state I'm after.

3

If you do not tell rsync to preserve the uid, then it will create all transferred files under the ownership of the user that you connected as. The key, then, is to make sure that you put 'remote-user' => 'bob' in the site alias for your destination site.

The rsync flags I use to achieve this are -rlptz. So, in my drushrc.php, I have:

$command_specific['rsync'] = array('mode' => 'rlptz');

See also:

http://drupal.org/node/1169776#comment-4612944

http://drupal.org/node/1343892

Supporting rsync modules in Drush would be awkward. If you want to use modules, it's probably best to call rsync directly. e.g.:

rsync -av --rsh=ssh drush dd @siteA root@siteB.loc::SiteB

You would need to configure your SiteB module to point to the Site B Drupal root anyway, so it seems like there is little value to tying this to a site alias.

  • Sorry, rsync does not support that feature. See man rsync. I prefer to create a wwwadmin user (separate from the webserver user) to own the web files. If you use ssh to fix up the permissions after the rsync, you will have to run it as the superuser or use sudo, the later being the preferred method. For an example of how to chain additional operations after a Drush command, see drupalcode.org/project/drush.git/blob/HEAD:/examples/… That chains a command after sql-sync, but you could do the same thing for drush rsync. – greg_1_anderson Mar 8 '12 at 18:08
  • actually, rsync DOES support such a feature: see EDIT 2# ^^^. trick is, now, if/how to get 'drush rsync' to use the rsyncd-invoking syntax – user6023 Mar 8 '12 at 18:57
  • Cool trick, customizing the rsyncd configuration. You could get drush to use the siteB.loc::SiteB syntax by putting that into 'remote-host', but doing that would mess up other uses of the site alias. Looks like it would be a worthwhile enhancement to drush rsync to allow some other option to specify append text to the target site. – greg_1_anderson Mar 8 '12 at 19:36
  • fyi, feature request @ -> https://drupal.org/node/1473524. in the meantime, putting siteB.loc::SiteB in remote-host of a task-dedicated alias might be an option. – user6023 Mar 8 '12 at 20:35
  • Feature request is probably a no-go; see Edit in answer above. – greg_1_anderson Mar 8 '12 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy