Rsync archive mode

archiversync

I have been reading plenty of articles regarding rsync and its -a switch. As per theory, I have understood that it preserves a lot of properties like permission, time, group, owner, etc., but why doesn't this work when I'm trying it?

There are two users sam and pam. I'm trying to rsync a file from /home/sam to /home/pam, while retaining its owner & group.

[sam@localhost sam]$ ll
-rwx---r-x 1 sam sam 0 Jul 18 18:39 abc

If I try to rsync (after logging as user pam), the copied files don't have sam as owner or group.

[pam@localhost pam]$ rsync -a /home/sam/* /home/pam
[pam@localhost pam]$ ll
-rwx---r-x 1 pam pam 0 Jul 18 18:39 abc

Why doesn't it retain owner and group for abc as sam?

Best Answer

Preserve owner (-o, included in -a) is a feature only available to the superuser (root). Preserve group (-g, included in -a) is limited to the case where the user running rsync (on the destination site) is a member of the group. Rsync behaves this way because on most unix variants, these are the cases where it's allowed to set the target file's owner and group.

You could either attempt the command using the root user, or add the option --super or --fake-super.

--super will still attempt to change owner and group, but only if the OS allows this. Not all operating systems will allow that, recent Solaris versions being a good example.

--fake-super will add extended attributes to the destination files to mimic (fake) owner and group of the file by adding permissions.

Related Question