0

rsync is not preserving permissions/ownesrship after file transfer. Here is the scenario

Source host(192.168.2.14 from where files are copied):

Source Path

 # ls -l "/shareddata/tesz/"
 total 4
 drwxrwsr-x 2 root admin 4096 Sep 15 19:38 web

 # ls -l /shareddata/tesz/web/
 total 0
 -rw-rw-r-- 1 askar admin 0 Sep 15 19:38 test1 
 -rw-rw-r-- 1 dey   admin 0 Sep 15 19:38 test2

Destination Path:

 # ls -ld /shareddata/
 drwxrwxr-x. 4 root admin 4096 Sep 15 19:44 /shareddata/

The rsync command we tried to copy the files is . The script is running under fsync user

$ id fsync
uid=700(fsync) gid=502(admin) groups=502(admin)


/usr/bin/rsync -rogp 192.168.2.14:/shareddata/tesz /shareddata/
/usr/bin/rsync -av 192.168.2.14:/shareddata/tesz /shareddata/

We are running the rsync command from the destination host where the files are copied to. But we can see that permissions/ownership not getting preserved after file transfer

$ ls -l /shareddata/
  total 8
       drwxrwsr-x 3 fsync admin 4096 Sep 15 19:44 tesz

 $ ls -l /shareddata/tesz/
 total 4
 drwxrwsr-x 2 fsync admin 4096 Sep 15 20:29 web

 $ ls -l /shareddata/tesz/web/
   total 0
   -rw-rw-r-- 1 fsync admin 0 Sep 15 20:29 test1
   -rw-rw-r-- 1 fsync admin 0 Sep 15 20:29 test2

What are the modifications I need in rsync command so that permissions are preserved.

  • 2
    You must be root to preserve ownership. – fd0 Sep 15 '15 at 11:15
  • We will not be able to do use root . Can we use sudo for fsync user to preserve ownership ? – Zama Ques Sep 15 '15 at 11:26
2

As mentioned in the comments the remote rsync process needs to be run with superuser privileges to be able to preserve permissions. If you have sudo access on the remote server you can use the --rsync-path option to run rsync as root:

rsync -av --rsync-path "sudo rsync" source/ server:/destination/
  • Is it a issue if I run it as , rsync -av --rsync-path "sudo rsync" server:/src /dst from the destination server – Zama Ques Sep 15 '15 at 14:12
  • 1
    In this case you should run sudo rsync ... to preserve permissions. You don't need --rsync-path as long as you can access all the source files/directories on the source server as the user you're connecting as. Hope that makes sense? – piit79 Sep 15 '15 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.