Answers to: Rsync backups using sudo instead of roothttp://linuxexchange.org/questions/411/rsync-backups-using-sudo-instead-of-root<p>I'm having a little rsync problem. I am trying to move data from one server to the next using rsync. The data needs to retain file owner and permission settings. The files in question are not owned by me, but my account (on both servers) does have sudo access.</p> <p>For example, I want to copy /var/www from server1 to server2. All files are owned by user www-data. My user account on both servers is <code>sander</code> and I have sudo rights on both servers.</p> <pre><code>server1$ sudo rsync -av /var/www/ sander@server2:/var/www </code></pre> <p>does not work, because sander@server2 cannot write to /var/www and cannot change the uid/gid to www-data.</p> <pre><code>server2$ sudo rsync -av sander@server1:/var/www/ /var/www </code></pre> <p>Does not work. sander@server1 cannot read /var/www.</p> <p>How do I solve this?</p>enSun, 09 May 2010 20:54:49 -0400Answer by gregularexpressionshttp://linuxexchange.org/questions/411/rsync-backups-using-sudo-instead-of-root/414<p>I found the following article, <a href="http://crashingdaily.wordpress.com/2007/06/29/rsync-and-sudo-over-ssh/" rel="nofollow">http://crashingdaily.wordpress.com/2007/06/29/rsync-and-sudo-over-ssh/</a> and one of the solutions seems to meet your needs (although I haven't tested it).</p> <p>If you ran the following on Server2:</p> <p>This line seems to enable the 'sudo tunnel' if you will:</p> <pre><code>stty -echo; ssh server1 sudo -v; stty echo </code></pre> <p>and then this the transfer causing rsync to run under sudo (I added the 'u' as then it will only copy over files that are newer or don't yet exist):</p> <pre><code>rsync -au -e "ssh" --rsync-path="sudo rsync" sander@server1:/var/www /var/www--progress </code></pre>gregularexpressionsSun, 09 May 2010 20:54:49 -0400http://linuxexchange.org/questions/411/rsync-backups-using-sudo-instead-of-root/414Answer by 1jnikehttp://linuxexchange.org/questions/411/rsync-backups-using-sudo-instead-of-root/413<p>You may want to try this!</p> <p>You may want to create a directory under your home directories under both servers; </p> <p><em>sander@server1:~/www/</em></p> <p><em>sander@server2:~/www/</em></p> <p><em><strong>Then</em></strong> </p> <p><em>server1$ sudo rsync -av /var/www/ sander@server1:~/www/</em></p> <p><em><strong>Then</em></strong> </p> <p><em>scp sander@server1:~/www/</em> sander@server2:~/www/*</p> <p><em><strong>Then on</em></strong></p> <p><em>server2$ sudo rsync -av sander@server2:~/www/ /var/www/</em></p> <p>This all depends on the permissions you have access to the directory /var/www/ on both servers; server1 &amp; server2.</p>1jnikeSun, 09 May 2010 20:51:56 -0400http://linuxexchange.org/questions/411/rsync-backups-using-sudo-instead-of-root/413