mnowotka mnowotka - 1 year ago 88
Linux Question

rsyncing between two non-login users

I have two machines

, both of which have 3 users:

  • root
    (I don't know a password can just switch using
    sudo su -

  • login
    (used for
    ing into both machines, has a password, is a sudoer)

  • mysql
    (standard non-interactive user running mysql server)

What I need to do is to rsync data directory (
) belonging to
from machine
to machine

Obviously I can't just do:

rsync -avpE /dir/ B:/dir/

Because neither A nor B have read access to

I can't do:

sudo -u mysql rsync -avpE /dir/ B:/dir/

Because now A has access to
but B doesn't.

So is it possible to construct an rsync command so I copy data across without using some temporary space?

Answer Source

rsync has an option called --rsync-path that might help you:

$ rsync |& grep rsync-path
     --rsync-path=PROGRAM    specify the rsync to run on the remote machine

The idea is to ask (the local) rsync to ssh to the remote machine (as user login) and then when it wants to call rsync on the remote machine, have it call sudo -u mysql rsync instead of plain rsync. So something like that:

sudo -u mysql rsync -avpE --rsync-path="sudo -u mysql rsync" /dir/ login@B:/dir/

Of course for this to work, the user login on the remote machine must be able to sudo -u mysql without a password.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download