-#!/bin/perl
+#!/usr/bin/perl
#============================================================= -*-perl-*-
#
# BackupPC_fixupBackupSummary: recreate backups file in case
# Craig Barratt <cbarratt@users.sourceforge.net>
#
# COPYRIGHT
-# Copyright (C) 2005 Craig Barratt
+# Copyright (C) 2005-2009 Craig Barratt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
#
#========================================================================
#
-# Version 2.1.0, released 20 Jun 2004.
+# Version 3.2.0, released 31 Jul 2010.
#
# See http://backuppc.sourceforge.net.
#
my @hostList;
our(%backupInfo);
+my %opts;
+
+if ( !getopts("l", \%opts) ) {
+ print STDERR <<EOF;
+usage: $0 [-l]
+ Options:
+ -l legacy mode: try to reconstruct backups from LOG
+ files for backups prior to BackupPC v3.0.
+EOF
+ exit(1);
+}
if ( !@ARGV ) {
@hostList = sort(keys(%$Hosts));
#
@Backups = $bpc->BackupInfoRead($host);
- #
- # Temporary: create backupInfo files in each backup
- # directory
- #
- foreach ( my $i = 0 ; $i < @Backups ; $i++ ) {
- BackupPC::Storage->backupInfoWrite($dir, $Backups[$i]{num},
- $Backups[$i]);
- if ( 0 ) {
- my $bkupNum = $Backups[$i]{num};
- if ( !-f "$dir/$bkupNum/backupInfo" ) {
- my($dump) = Data::Dumper->new(
- [ $Backups[$i]],
- [qw(*backupInfo)]);
- $dump->Indent(1);
- if ( open(BKUPINFO, ">", "$dir/$bkupNum/backupInfo") ) {
- print(BKUPINFO $dump->Dump);
- close(BKUPINFO);
- }
- }
- }
- }
-
#
# Look through the LOG files to get information about
# completed backups. The data from the LOG file is
my @files = readdir(DIR);
closedir(DIR);
foreach my $file ( @files ) {
- if ( $file =~ /^LOG(.\d+\.z)?/ ) {
+ if ( $opts{l} && $file =~ /^LOG(.\d+\.z)?/ ) {
push(@LogFiles, $file);
} elsif ( $file =~ /^(\d+)$/ ) {
my $bkupNum = $1;
#
@LogFiles = sort({-M "$dir/$a" <=> -M "$dir/$b"} @LogFiles);
my $startTime;
+ my $fillFromNum;
foreach my $file ( @LogFiles ) {
my $f = BackupPC::FileZIO->open("$dir/$file", 0, $file =~ /\.z/);
}
print(" Reading $file\n");
while ( (my $str = $f->readLine()) ne "" ) {
- if ( $str =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (full|incr|partial) backup started for directory / ) {
- $startTime = $str;
+ if ( $str =~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (full|incr|partial) backup started / ) {
+ $startTime = parsedate($1);
next;
}
next if ( $str !~ /^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (full|incr|partial) backup (\d+) complete, (\d+) files, (\d+) bytes, (\d+) xferErrs \((\d+) bad files, (\d+) bad shares, (\d+) other\)/ );
- my $endTime = $1;
my $type = $2;
my $bkupNum = $3;
my $nFilesTotal = $4;
my $xferErrs = $6;
my $badFiles = $7;
my $badShare = $8;
+ my $endTime = parsedate($1);
print(" Got $type backup $bkupNum at $endTime\n");
- next if ( !-d "$dir/$2" );
+ next if ( !-d "$dir/$bkupNum" );
$BkupFromLOG->{$bkupNum} = {
num => $bkupNum,
type => $type,
- startTime => parsedate($startTime),
- endTime => parsedate($endTime),
+ startTime => $startTime,
+ endTime => $endTime,
size => $sizeTotal,
nFiles => $nFilesTotal,
xferErrs => $xferErrs,
noFill => $type eq "incr" ? 1 : 0,
level => $type eq "incr" ? 1 : 0,
mangle => 1,
- noFill => $noFill;
- fillFromNum => $fillFromNum;
+ fillFromNum => $fillFromNum,
};
+ $fillFromNum = $bkupNum if ( $type eq "full" );
}
}
- splice(@Backups, 2, 1);
-
#
# Now merge any info from $BkupFromInfo and $BkupFromLOG
# that is missing from @Backups.
if ( $changes ) {
@Backups = sort({$a->{num} <=> $b->{num}} @Backups);
- print Dumper \@Backups;
+ # print Dumper \@Backups;
+ $bpc->BackupInfoWrite($host, @Backups);
} else {
print(" No changes for host $host\n");
}