Automatically generating usermap and groupmap for rsync
I recently had to restore a server from backup after rebuilding it, and ran into a problem I've only encountered occasionally: The user and group IDs were different on the new server configuration compared to the backup. For example, the user "prosody" was user 121 on the old build and 109 on the new one. Just restoring with rsync would leave files with the wrong owners and groups, which could lead to various security issues (and downtime and bugs, of course.) The backup was full of mystery-meat owners and groups.
Luckily, I also had a backup of
/etc/passwd
and /etc/group
,
and I was able to write a script to work these into an rsync command.