Rsync – How to Preserve File and Folder Permissions

backuplinuxpermissionsrsync

I maintain a backup of my email accounts using this command:

sudo rsync -av --delete --progress -e "ssh -p pNumber" --rsync-path="/usr/bin/rsync" /vmail/ user@my_backup_server:/home/user/backups/vmail/

Source:
Most email folders are owned by user vmail.

Destination (backup server):
System doesn't have a user named vmail.

My question, would the above command preserve file and directory permissions even if destination machine doesn't have a user named vmail? Would it be possible to restore the files and permissions completely from destination to source even if the user names between the two machines are not the same (some missing on backup server).

Best Answer

What rsync copies is the numerical user id of the file, regardless if it exists on the target system. If a user with that id doesn't exist, ls etc. will just show that number instead of a name. If that user id belongs to another username on the target system, this user will now own the file.

Backup and restore will work without a problem in this scenario.