rsync: Modify file ownership during transfers

A couple of weeks ago, I had to merge two seperate Linux systems into a single one. Obviously, I had to keep and migrate all the home directories as well. Therefore, I added all missing users on the ‘target system’ and simply restored the home directories from a backup (which was way easier due to my configuration). Since there were no recent changes, I could simply ignore the ‘gap’ of a couple of hours between the last backup run and the current time.

The problem: Since the primary purpose of the backup is to allow a full restore of the system, it is being created with the --numeric-ids parameter. This lead to a mismatch of the file permissions on the ‘target system’ since I didn’t match the user and group IDs beforehand.

The solution: rsync provides the option --chown=user:gruppe that allows setting the file and directory ownership while copying the files to the target system. The complete call to rsync looks like this:

backup-server ~ # for I in user1 user2 user3; do rsync -Pavz -e "ssh -i backup_key_id_rsa" ./home/$I root@target:/home --chown=$I:$I; done

I’m currently asking myself if it even makes sens to use --numeric-ids for a backup that’s meant to be fully restored to a (new) machine…

Leave a Reply

Your email address will not be published.