Please note that LinuxExchange will be shutting down on December 31st, 2016. Visit this thread for additional information and to provide feedback.

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.

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 sander and I have sudo rights on both servers.

server1$ sudo rsync -av /var/www/ sander@server2:/var/www

does not work, because sander@server2 cannot write to /var/www and cannot change the uid/gid to www-data.

server2$ sudo rsync -av sander@server1:/var/www/ /var/www

Does not work. sander@server1 cannot read /var/www.

How do I solve this?

asked 09 May '10, 20:09

Sander%20Marechal's gravatar image

Sander Marechal
398116
accept rate: 29%




I found the following article, http://crashingdaily.wordpress.com/2007/06/29/rsync-and-sudo-over-ssh/ and one of the solutions seems to meet your needs (although I haven't tested it).

If you ran the following on Server2:

This line seems to enable the 'sudo tunnel' if you will:

stty -echo; ssh server1 sudo -v; stty echo 

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):

rsync -au -e "ssh" --rsync-path="sudo rsync" sander@server1:/var/www /var/www--progress
link

answered 09 May '10, 20:54

gregularexpressions's gravatar image

gregularexpr...
197117
accept rate: 50%

Thanks, this worked!

(10 May '10, 10:17) Sander Marechal

You may want to try this!

You may want to create a directory under your home directories under both servers;

sander@server1:~/www/

sander@server2:~/www/

Then

server1$ sudo rsync -av /var/www/ sander@server1:~/www/

Then

scp sander@server1:~/www/ sander@server2:~/www/*

Then on

server2$ sudo rsync -av sander@server2:~/www/ /var/www/

This all depends on the permissions you have access to the directory /var/www/ on both servers; server1 & server2.

link

answered 09 May '10, 20:51

1jnike's gravatar image

1jnike
961
accept rate: 8%

Sorry, I have to downvote this. Your solution does not retain uid/gid and permission setting like I asked for. Sorry.

(10 May '10, 10:14) Sander Marechal
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×10
×3
×1

Asked: 09 May '10, 20:09

Seen: 11,009 times

Last updated: 09 May '10, 20:54

powered by OSQA