Thanks for John Goerzen for nudging me in the right direction.
When you backup to a remote machine you loose the ownership information on your files, because you are logging in a as a normal user with - say - uid 1000. Then all files created are of uid 1000.
(for gid the same holds, but I'll skip that for this story).
rdup does have this information, but it is not used when
doing a remote backup. For local backups this normally is not
a problem because that runs as root. And the root user can
set the ownership.
So, how can we fix this? We would need the original user and group information. The best spot for this would be rdup's internal file list. Unfortunately this info is not saved there. This is why I'm going to change that for the next rdup release (0.8.0).
If the user/group info is stored in the file, you can do the following.
- Transfer this file to you backup medium
- Convert it to a normal rdup list
- Feed this list to
rdup-tr, which read the file back from disk - Feed
rdup-tr's output tordup-upto re-create the files;rdup-upmust then run with root permissions.
Or in code:
Step 1.
rdup -N timestamp LIST ~/bin | rdup-tr | \
ssh miekg@remotehost rdup-up -t /tmp/boe/backup
scp LIST miekg@remotehost /tmp/boe/backup
Step 2 + 3 + 4.
As root:
ssh miekg@remotehost "path-tr.pl < LIST | rdup-tr -c" | rdup-up /new
I have not test this (yet) but it seems like a workable solution. The
code of path-tr.pl is listed below. Again: there is still no uid/gid
information in the internal filelist, so currently this WILL NOT WORK.
This stuff is still in the early stages and eventually I will
incorporate it in rdup-simple.
path-tr.pl
For converting an internal rdup list in normal rdup output. Here we
always substitute 1000/1000 for the uid/gid information and I'm
prefixing it with the backup path /vol/backup in the variable
$prefix so the rdup-tr may actually find the files.
#!/usr/bin/perl
use Fcntl ':mode';
use feature 'switch';
use warnings;
use strict;
# convert rdup's internal list to rdup output
# if you save this list on your backup. You
# can backup as a normal user and save the
# original user/group info.
#
# If you feed this to rdup-tr you get your
# backup back in the original state
# (otherwise all files would user/user, where
# user is the user running the ssh)
# Internal list looks like: (may change)
# # mode dev inode linktype pathlen filesize path
# 16877 2309 2 * 5 4096 /home
#
# rdup output looks like
# #type perm user/group pathlen filesize path
# +d 0755 0 0 5 0 /home
use constant {
MODE => 0,
DEV => 1,
INODE => 2,
LINK => 3,
PLEN => 4,
FSIZE => 5,
PATH => 6
};
my $prefix = "/vol/backup";
my $prelen = length($prefix);
my @p;
<>;
while (<>) {
chomp;
@p = split / /, $_, 7;
if (S_ISDIR($p[MODE])) { $p[FSIZE] = 0; }
if (defined $prefix) {
$p[PLEN] += $prelen;
$p[PATH] = $prefix . $p[PATH];
}
# plusmin
print "+";
# type, trying out the new Perl 5.10 stuff
given ($p[MODE]) {
when (S_ISDIR $_) {
print "d";
}
when (S_ISREG $_) {
if ($p[LINK] eq 'h') { print "h"; }
if ($p[LINK] eq '*') { print "-"; }
}
when (S_ISLNK $_) {
print "l";
}
# ...
}
# perms
printf " %04o", $p[MODE] & 07777;
# user/group (don't have that info (yet))
print " 1000 1000";
# pathlen
printf " %s %s %s\n", $p[PLEN], $p[FSIZE], $p[PATH];
}

