Restoring from backup, preserving uids

Neil Gunton neil at nilspace.com
Sat Aug 2 20:50:06 GMT 2008


Wayne Davison wrote:
> 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 <==
> #!/usr/bin/perl
> while (<>) {
>     push @_, "$2:$1" if /^(\w+):[^:]+:(\d+)/;
> }
> print join(',', @_), "\n";
> 
> ==> support/mapto <==
> #!/usr/bin/perl
> 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
> daemon).
> 
> ..wayne..

Thanks. The point of my original message wasn't so much to get a 
workaround, as to suggest a new option for rsync that would make this 
kind of task easier.

That above perl solution sounds very complex. What I was suggesting was 
a way to improve rsync by adding an option to utilize your old passwd 
file directly, via a simple new command line option - something like 
--src-passwd=path-to-file or whatever. I know that rsync uses system 
calls to access uids and whatnot, but surely it wouldn't be that complex 
to add a layer above those calls, which could differentiate between the 
system calls for the default case, or parsing the passwd file for the 
src if that option was presented. The passwd files are not that complex 
in structure - simple text, with a fairly predictable format. Of course, 
I'm not the developer here (though it doesn't sound like too complex a 
refactoring to me), and I'm basically asking someone else to do work 
here, so I guess I'll just leave it at that. I do realise that all sorts 
of workarounds exist, but the one you presented above sounds really 
complicated. The whole point of rsync in the first place was to simplify 
backing up - I mean, you could have done what rsync does using a bunch 
of perl code, but someone decided to try to make it simpler. I think the 
old/new uid issue is very common, given the scenario of backing up your 
system to something like a a local USB hard drive and then trying to 
restore your config to a newly installed system. I really think it would 
be a fantastic addition to rsync to build this in as a simple option, 
rather than having to jump through even more hoops just to do something 
that should really be quite simple (imho). I just wanted to throw the 
idea out there, the rsync developers can use it or not, of course. 
Unfortunately, while I am an experienced developer, I have never looked 
at the rsync code and have no idea how involved it would be to get into 
it and do the changes myself - and I don't have time at present.

Anyway - thanks for listening,

Neil


More information about the rsync mailing list