Using rsync to mirror directories where root owns file, using non-root user to initiate session
PEOPLES, MICHAEL P
mp4783 at att.com
Fri Jun 22 14:03:38 MDT 2012
It appears to be working. Here is a sample command line, which I initiate from the source server:
rsync -avPxHz --rsync-path='sudo /usr/bin/rsync' -e "ssh -i /home/rsyncusr/.ssh/id_rsa" /tmp/rsynctest/ rsyncusr at remoteserver.att.com:/tmp/rsynctest/
On the remote server, I had to add the following entry to sudoers:
rsyncusr ALL=(ALL) NOPASSWD:/usr/bin/rsync
I added the "-i <path to private key>" to the "-e" option so that no password was necessary when logging into the remote server using the rsyncusr account. This, of course, required setting this up in advance.
I removed the "--delete" option because I did not want to overwrite files.
I removed the --numeric-ids because the UID of the users may not necessarily be the same.
This command line copies everything in the /tmp/rsynctest directory on the source server to the /tmp/rsynctest directory on the remote server, preserving all ownership and permissions.
Thank you very much for helping me out.
Michael Peoples (mp4783)
Senior Systems Manager
AT&T - ATTSI
mpeoples at att.com
This e-mail and any files transmitted with it are AT&T property, are confidential, and are intended solely for the use of the individual or entity to whom this email is addressed. If you are not one of the named recipient(s) or otherwise have reason to believe that you have received this message in error, please notify the sender and delete this message immediately from your computer. Any other use, retention, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited."
From: Matthias Schniedermeyer [mailto:ms at citd.de]
Sent: Friday, June 22, 2012 4:51 AM
To: PEOPLES, MICHAEL P
Cc: rsync at lists.samba.org
Subject: Re: Using rsync to mirror directories where root owns file, using non-root user to initiate session
On 20.06.2012 22:26, PEOPLES, MICHAEL P wrote:
> I have spent a day researching and attempting to debug this issue. I am hoping someone can tell me how (or disabuse me of the delusion that it's possible) to do the following:
If running a command as root via sudo is acceptable. I had the exact
same problem 2 days ago. I had to backup a machine where i only got a
user-login, with sudo privilege.
So after some googleing i tried (As root on the target machine, but
you can also sudo that):
rsync -avPxHz --delete --numeric-ids --rsync-path='sudo rsync' -e ssh user at remote:/ ./
and it worked, of course that only works if (remote) sudo doesn't ask
for a password.
Real Programmers consider "what you see is what you get" to be just as
bad a concept in Text Editors as it is in women. No, the Real Programmer
wants a "you asked for it, you got it" text editor -- complicated,
cryptic, powerful, unforgiving, dangerous.
More information about the rsync