X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_dump;h=7c3e33c43ab16daccdd410ee28ed20dbba4e7a37;hp=7ba9e3e2ac89b32ccebf27e35666aa29efe2efe8;hb=197383fe39b33180b648de9e4bcc1fd7b7ca6a66;hpb=617af75f7419e95a9c3ea05b05cf21957acc331c diff --git a/bin/BackupPC_dump b/bin/BackupPC_dump index 7ba9e3e..7c3e33c 100755 --- a/bin/BackupPC_dump +++ b/bin/BackupPC_dump @@ -52,7 +52,7 @@ # Craig Barratt # # COPYRIGHT -# Copyright (C) 2001-2003 Craig Barratt +# Copyright (C) 2001-2007 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 @@ -70,7 +70,7 @@ # #======================================================================== # -# Version 3.0.0alpha, released 23 Jan 2006. +# Version 3.1.0beta0, released 3 Sep 2007. # # See http://backuppc.sourceforge.net. # @@ -86,6 +86,7 @@ use BackupPC::Xfer::Smb; use BackupPC::Xfer::Tar; use BackupPC::Xfer::Rsync; use BackupPC::Xfer::BackupPCd; +use Encode; use Socket; use File::Path; use File::Find; @@ -207,12 +208,12 @@ if ( !-f $logPath ) { unlink($file); next; } + $lastLog--; next if ( $file =~ /\.z$/ || !$Conf{CompressLevel} ); BackupPC::FileZIO->compressCopy($file, "$file.z", undef, $Conf{CompressLevel}, 1); - $lastLog--; } } @@ -302,6 +303,8 @@ my $lastFullTime = 0; my $lastIncrTime = 0; my $partialIdx = -1; my $partialNum; +my $partialFileCnt; +my $lastBkupNum; my $lastPartial = 0; # @@ -332,23 +335,10 @@ if ( !$opts{i} && !$opts{f} && $Conf{BlackoutGoodCnt} >= 0 my($currHours) = $hour + $min / 60 + $sec / 3600; my $blackout; - # - # Handle backward compatibility with original separate scalar - # parameters. - # - if ( defined($Conf{BlackoutHourBegin}) ) { - push(@{$Conf{BlackoutPeriods}}, - { - hourBegin => $Conf{BlackoutHourBegin}, - hourEnd => $Conf{BlackoutHourEnd}, - weekDays => $Conf{BlackoutWeekDays}, - } - ); - } foreach my $p ( @{$Conf{BlackoutPeriods}} ) { # - # Allow blackout to span midnight (specified by BlackoutHourBegin - # being greater than BlackoutHourEnd) + # Allow blackout to span midnight (specified by hourBegin + # being greater than hourEnd) # next if ( ref($p->{weekDays}) ne "ARRAY" || !defined($p->{hourBegin}) @@ -399,25 +389,27 @@ my(@lastIdxByLevel, $incrCntSinceFull); # as a starting point for an incremental. # @Backups = $bpc->BackupInfoRead($client); -## @Backups = sort( { $a->{startTime} <=> $b->{startTime} }, @Backups); for ( my $i = 0 ; $i < @Backups ; $i++ ) { $needLink = 1 if ( $Backups[$i]{nFilesNew} eq "" || -f "$Dir/NewFileList.$Backups[$i]{num}" ); if ( $Backups[$i]{type} eq "full" ) { $incrCntSinceFull = 0; + $lastBkupNum = $Backups[$i]{num}; $lastIdxByLevel[0] = $i; if ( $lastFullTime < $Backups[$i]{startTime} ) { $lastFullTime = $Backups[$i]{startTime}; } } elsif ( $Backups[$i]{type} eq "incr" ) { $incrCntSinceFull++; + $lastBkupNum = $Backups[$i]{num}; $lastIdxByLevel[$Backups[$i]{level}] = $i; $lastIncrTime = $Backups[$i]{startTime} if ( $lastIncrTime < $Backups[$i]{startTime} ); } elsif ( $Backups[$i]{type} eq "partial" ) { - $partialIdx = $i; - $lastPartial = $Backups[$i]{startTime}; - $partialNum = $Backups[$i]{num}; + $partialIdx = $i; + $lastPartial = $Backups[$i]{startTime}; + $partialNum = $Backups[$i]{num}; + $partialFileCnt = $Backups[$i]{nFiles}; } } @@ -429,6 +421,8 @@ if ( @Backups == 0 || (!$opts{i} && (time - $lastFullTime > $Conf{FullPeriod} * 24*3600 && time - $lastIncrTime > $Conf{IncrPeriod} * 24*3600)) ) { $type = "full"; + $incrLevel = 0; + $incrBaseBkupNum = $lastBkupNum; } elsif ( $opts{i} || (time - $lastIncrTime > $Conf{IncrPeriod} * 24*3600 && time - $lastFullTime > $Conf{IncrPeriod} * 24*3600) ) { $type = "incr"; @@ -446,7 +440,7 @@ if ( @Backups == 0 my $idx = $lastIdxByLevel[$i]; next if ( !defined($idx) ); if ( !defined($incrBaseTime) - || $Backups[$idx]{startTime} < $incrBaseTime ) { + || $Backups[$idx]{startTime} > $incrBaseTime ) { $incrBaseBkupNum = $Backups[$idx]{num}; $incrBaseLevel = $Backups[$idx]{level}; $incrBaseTime = $Backups[$idx]{startTime}; @@ -456,11 +450,27 @@ if ( @Backups == 0 # Can't find any earlier lower-level backup! Shouldn't # happen - just do full instead # - $type = "full" if ( !defined($incrBaseBkupNum) || $incrLevel < 1 ); + if ( !defined($incrBaseBkupNum) || $incrLevel < 1 ) { + $type = "full"; + $incrBaseBkupNum = $lastBkupNum; + } } else { NothingToDo($needLink); } +if ( !$bpc->HardlinkTest($Dir, "$TopDir/cpool") ) { + print(LOG $bpc->timeStamp, "Can't create a test hardlink between a file" + . " in $Dir and $TopDir/cpool. Either these are different" + . " file systems, or this file system doesn't support hardlinks," + . " or these directories don't exist, or there is a permissions" + . " problem, or the file system is out of inodes or full. Use" + . " df, df -i, and ls -ld to check each of these possibilities." + . " Quitting...\n"); + print("test hardlink between $Dir and $TopDir/cpool failed\n"); + print("link $clientURI\n") if ( $needLink ); + exit(1); +} + # # Check if $host is alive # @@ -586,6 +596,10 @@ $NeedPostCmd = 1; for my $shareName ( @$ShareNames ) { local(*RH, *WH); + # + # Convert $shareName to utf8 octets + # + $shareName = encode("utf8", $shareName); $stat{xferOK} = $stat{hostAbort} = undef; $stat{hostError} = $stat{lastOutputLine} = undef; if ( -d "$Dir/new/$shareName" ) { @@ -763,6 +777,7 @@ for my $shareName ( @$ShareNames ) { close(WH); } print(LOG $bpc->timeStamp, $logMsg, "\n"); + $XferLOG->write(\"$logMsg\n"); print("started $type dump, share=$shareName\n"); pidHandler(@xferPid); @@ -874,7 +889,7 @@ for my $shareName ( @$ShareNames ) { $stat{xferOK} = 0 if ( $stat{hostError} || $stat{hostAbort} ); if ( !$stat{xferOK} ) { # - # kill off the tranfer program, first nicely then forcefully + # kill off the transfer program, first nicely then forcefully # if ( @xferPid ) { kill($bpc->sigName2num("INT"), @xferPid); @@ -907,6 +922,15 @@ if ( $type eq "full" && $stat{hostError} eq "" $stat{xferOK} = 0 if ( $Abort ); +# +# If there is no "new" directory then the backup is bad +# +if ( $stat{xferOK} && !-d "$Dir/new" ) { + $stat{hostError} = "No backup directory $Dir/new" + if ( $stat{hostError} eq "" ); + $stat{xferOK} = 0; +} + # # Do one last check to make sure it is still the machine we expect. # @@ -1011,9 +1035,9 @@ sub catch_signal "Aborting backup up after signal $sigName\n"); # - # Tell xfer to abort + # Tell xfer to abort, but only if we actually started one # - $xfer->abort($reason); + $xfer->abort($reason) if ( defined($xfer) ); # # Send ALRMs to BackupPC_tarExtract if we are using it @@ -1106,7 +1130,9 @@ sub BackupFailCleanup # # We keep this backup if it is a full and we actually backed - # up some files. + # up some files. If the prior backup was a partial too, we + # only keep this backup if it has more files than the previous + # partial. # if ( $type eq "full" ) { if ( $nFilesTotal == 0 && $xfer->getStats->{fileCnt} == 0 ) { @@ -1115,13 +1141,29 @@ sub BackupFailCleanup # directory just in case. # find(\&CheckForNewFiles, "$Dir/new"); - $keepPartial = 1 if ( $nFilesTotal ); - } else { - # - # Xfer reported some files - # + } + my $str; + if ( $nFilesTotal > $partialFileCnt + || $xfer->getStats->{fileCnt} > $partialFileCnt ) { + # + # If the last backup wasn't a partial then + # $partialFileCnt is undefined, so the above + # test is simply $nFilesTotal > 0 + # $keepPartial = 1; - } + if ( $partialFileCnt ) { + $str = "Saving this as a partial backup\n"; + } else { + $str = sprintf("Saving this as a partial backup, replacing the" + . " prior one (got %d and %d files versus %d)\n", + $nFilesTotal, $xfer->getStats->{fileCnt}, $partialFileCnt); + } + } else { + $str = sprintf("Not saving this as a partial backup since it has fewer" + . " files than the prior one (got %d and %d files versus %d)\n", + $nFilesTotal, $xfer->getStats->{fileCnt}, $partialFileCnt); + } + $XferLOG->write(\$str); } # @@ -1275,6 +1317,7 @@ sub BackupExpire # where $Conf{FullKeepCnt} is an array. # last if ( !BackupFullExpire($client, \@Backups) ); + $changes++; } $bpc->BackupInfoWrite($client, @Backups) if ( $changes ); } @@ -1377,6 +1420,7 @@ sub BackupSave # (the new backup might also be a partial, but that's ok). # BackupPartialRemove($client, \@Backups); + $needLink = 1 if ( -f "$Dir/NewFileList" ); # # Number the new backup @@ -1389,8 +1433,8 @@ sub BackupSave if ( !rename("$Dir/new", "$Dir/$num") ) { print(LOG $bpc->timeStamp, "Rename $Dir/new -> $Dir/$num failed\n"); $stat{xferOK} = 0; + return; } - $needLink = 1 if ( -f "$Dir/NewFileList" ); # # Add the new backup information to the backup file @@ -1415,6 +1459,7 @@ sub BackupSave $Backups[$i]{mangle} = 1; # name mangling always on for v1.04+ $Backups[$i]{xferMethod} = $Conf{XferMethod}; $Backups[$i]{charset} = $Conf{ClientCharset}; + $Backups[$i]{version} = $bpc->Version(); # # Save the main backups file #