mnowotka mnowotka - 2 months ago 13
Linux Question

rsyncing between two non-login users

I have two machines

A
and
B
, both of which have 3 users:


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

  • login
    (used for
    ssh
    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 (
dir
) belonging to
mysql
from machine
A
to machine
B
.

Obviously I can't just do:

rsync -avpE /dir/ B:/dir/


Because neither A nor B have read access to
dir


I can't do:

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


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

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

Answer

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.

Comments