Restoring from backup, preserving uids

Wayne Davison wayned at
Sat Aug 2 20:35:49 GMT 2008

On Sat, Aug 02, 2008 at 08:26:47AM -0500, Neil Gunton wrote:
> However if I reinstall Linux, and try to restore from the backup hard
> drive, the owner permissions get all mixed up, I assume since the
> numeric uids don't match up with the equivalent usernames any more.

One option is to try usermap.diff in the patches dir.  This provides
a simple user+group mapping facility that could be used to handle a
reasonably-sized set of users and groups (it is not written to handle
huge numbers of mapping rules, though).

For instance, the latest version of the patch will come with these
two helper scripts (that differ only in the order they output the
user and ID values):

==> support/mapfrom <==
while (<>) {
    push @_, "$2:$1" if /^(\w+):[^:]+:(\d+)/;
print join(',', @_), "\n";

==> support/mapto <==
while (<>) {
    push @_, "$1:$2" if /^(\w+):[^:]+:(\d+)/;
print join(',', @_), "\n";

You could do a copy from a backup by doing this:

rsync -av --usermap=`mapfrom /backup/etc/passwd` \
    --groupmap=`mapfrom /backup/etc/group` \
    /backup/dir /dest/

I briefly looked at potentially making these options handle a filename,
but I didn't want to over-complicate them.  Having an alternate means of
doing uid/gid lookups would probably be a better match for something
that would support files, and there's a daemon version of an alternate
name mapper available in the patches/nameconverter.diff file (but I
haven't decided how much I like that idea yet, and it only supports a


More information about the rsync mailing list