rsync -a not preserving file ownership or group

Solution 1:

I encountered the same problem and found a solution that worked for me. I created a Sparse Image called Backup. On a hard drive directory, file ownership was preserved during the rsync backup but not on the backup image.

1. Ownership of the Destination

I noticed that the ownership of the backup image was the current user (me) and I changed to something like that:

drwxrwx---@ 13 root    staff   510B 12 jul 10:59 Backup

2. Run rsync as sudo

And on the Linux host I modified the command to run rsync as sudo.

rsync -avh --rsync-path="sudo rsync" ...

And for the macOS backup host accept to execute rsync as sudo without password:

sudo visudo
# and add this line
# replace username with your current user name.
username ALL= NOPASSWD:/usr/bin/rsync

I also added these flags to the command but I cannot say that this would help to resolve the current problem:

/usr/bin/rsync -avzh  --sparse --super --numeric-ids --relative --rsync-path="sudo rsync" ...

Hope this help.