3 # try to recover pc/hostname/backups file from existing transfer logs
6 #use lib "__INSTALLDIR__/lib";
7 use lib "/data/backuppc/lib";
10 use BackupPC::FileZIO;
14 my $bpc = BackupPC::Lib->new(undef, undef, 1) or die "BackupPC::Lib->new failed\n";
16 my $TopDir = $bpc->TopDir();
17 my %Conf = $bpc->Conf();
19 my $host = shift @ARGV || die "usage: $0 hostname\n";
21 my $pc_dir = "$TopDir/pc/$host";
23 print "working in $pc_dir\n";
26 my $file = shift || die "no file?";
28 if ($file =~ m/XferLOG\.(\d+)/) {
31 die "can't extract number from $file";
37 extract_num($a) <=> extract_num($b)
38 } glob("$pc_dir/XferLOG.[0-9]*");
40 print "found ", $#logs + 1, " XferLOG files for $host\n";
42 print "\t",join("\n\t", @logs),"\n";
44 my $backups_file = "$pc_dir/backups";
46 if (-e $backups_file) {
48 my @old_backups = $bpc->BackupInfoRead($host);
49 print "found ", $#old_backups + 1, " backups in $pc_dir/backups\n";
51 #print Dumper(\@old_backups);
54 print "WARNING: backups file $backups_file doesn't exist, creating new one\n";
59 foreach my $xfer_log (@logs) {
61 my $num = extract_num($xfer_log);
64 my $attrib_file = "$pc_dir/$num/attrib";
65 die "can't find $attrib_file: $!" unless (-e $attrib_file);
67 my $startTime = (stat($attrib_file))[9]; # mtime
68 my $endTime = (stat($attrib_file))[10]; # ctime
74 print "working on $xfer_log $host #$num\n";
76 my $xfer_fh = BackupPC::FileZIO->open($xfer_log, 0, $Conf{CompressLevel});
77 while ( my $line = $xfer_fh->readLine() ) {
79 if ($line =~ m#^\s+(create|pool|delete|same|link)\s+(.)\s\d\d\d\s+\d+/\d+\s+(\d+)\s(.+)$#) {
80 my ($type,$is_dir,$size,$path) = ($1,$2,$3);
81 #print "$type [$is_dir] $size $path\n";
83 next if ($is_dir eq 'd');
85 if ($type eq 'pool' || $type eq 'same') {
88 } elsif ($type ne 'delete') {
94 print "#SKIP:$line<-\n";
102 startTime => $startTime,
105 nFiles => $nFilesTotal,
106 xferErrs => 0, # bogus
107 xferBadFile => 0, # bogus
108 xferBadShare => 0, # bogus
109 nFilesExist => $nFilesExist,
110 sizeExist => $sizeExist,
111 sizeExistComp => $sizeExist, # bogus
112 tarErrs => 0, # bogus
113 compress => $Conf{CompressLevel} ,
114 noFill => $type eq "incr" ? 1 : 0,
115 level => $type eq "incr" ? 1 : 0,
116 mangle => 1, # name mangling always on for v1.04+
119 push @new_backups, $this_backup;
120 $bpc->BackupInfoWrite($host, @new_backups);