run rsync as root but keep user ownership

Solution 1:

Use the -a flag, which includes among other things, the options -o and -g, which preserves owners and groups. This requires that you run rsync as root.

Also, see man rsync.

Solution 2:

Keeping the permissions is achieved through "archive" mode, -a. The common example is -avz:

rsync -avz foo:src/bar/ /data/bar

This ensures that symbolic links, devices, attributes, permissions, ownerships, etc. are preserved in the transfer. Additionally, compression will be used to reduce the size of data portions of the transfer.


Solution 3:

If you're using rsync for backup I can really recommend using rsnapshot instead (it uses rsync). It rotates the backups and uses hard links so you can see differences between your daily backups (but folders still look like they have the complete contents). I use this for backing up both Windows and Linux servers at work. Perfect for us!

Tags:

Linux

Rsync