X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_dump;h=8151cbd0df6dd4f178d7cc44a9962dbb5d90ad2a;hp=2b1d300077b768fdca7cbe6a0df1d0369035f23f;hb=17dcbbebb871212f90b81bb97f8d1feb528bdc43;hpb=ce708288691ba7dd95a8dac7a468bc0e4c1d6588 diff --git a/bin/BackupPC_dump b/bin/BackupPC_dump index 2b1d300..8151cbd 100755 --- a/bin/BackupPC_dump +++ b/bin/BackupPC_dump @@ -70,7 +70,7 @@ # #======================================================================== # -# Version 2.1.0beta0, released 20 Mar 2004. +# Version 2.1.0, released 20 Jun 2004. # # See http://backuppc.sourceforge.net. # @@ -276,18 +276,20 @@ my $lastFull = 0; my $lastIncr = 0; my $partialIdx = -1; my $partialNum; +my $lastPartial = 0; if ( $Conf{FullPeriod} == -1 && !$opts{f} && !$opts{i} || $Conf{FullPeriod} == -2 ) { print(STDERR "Exiting because backups are disabled with" - . "\$Conf{FullPeriod} = $Conf{FullPeriod}\n") if ( $opts{v} ); + . " \$Conf{FullPeriod} = $Conf{FullPeriod}\n") if ( $opts{v} ); # # Tell BackupPC to ignore old failed backups on hosts that # have backups disabled. # print("backups disabled\n") - if ( $StatusHost{reason} ne "Reason_backup_done" - && time - $StatusHost{startTime} > 2 * 24 * 3600 ); + if ( defined($StatusHost{errorTime}) + && $StatusHost{reason} ne "Reason_backup_done" + && time - $StatusHost{errorTime} > 4 * 24 * 3600 ); NothingToDo($needLink); } @@ -346,7 +348,7 @@ if ( !$opts{i} && !$opts{f} && $Conf{BlackoutGoodCnt} >= 0 } if ( !$opts{i} && !$opts{f} && $StatusHost{backoffTime} > time ) { - printf(LOG "%sskipping because of user requested delay (%.1f hours left)", + printf(LOG "%sskipping because of user requested delay (%.1f hours left)\n", $bpc->timeStamp, ($StatusHost{backoffTime} - time) / 3600); NothingToDo($needLink); } @@ -374,8 +376,9 @@ for ( my $i = 0 ; $i < @Backups ; $i++ ) { $lastIncr = $Backups[$i]{startTime} if ( $lastIncr < $Backups[$i]{startTime} ); } elsif ( $Backups[$i]{type} eq "partial" ) { - $partialIdx = $i; - $partialNum = $Backups[$i]{num}; + $partialIdx = $i; + $lastPartial = $Backups[$i]{startTime}; + $partialNum = $Backups[$i]{num}; } } @@ -431,7 +434,11 @@ $bpc->RmTreeDefer("$TopDir/trash", "$Dir/new") if ( -d "$Dir/new" ); # # Setup file extension for compression and open XferLOG output file # -$Conf{CompressLevel} = 0 if ( !BackupPC::FileZIO->compOk ); +if ( $Conf{CompressLevel} && !BackupPC::FileZIO->compOk ) { + print(LOG $bpc->timeStamp, "dump failed: can't find Compress::Zlib\n"); + print("dump failed: can't find Compress::Zlib\n"); + exit(1); +} my $fileExt = $Conf{CompressLevel} > 0 ? ".z" : ""; my $XferLOG = BackupPC::FileZIO->open("$Dir/XferLOG$fileExt", 1, $Conf{CompressLevel}); @@ -443,10 +450,10 @@ if ( !defined($XferLOG) ) { } # -# Ignore the partial dump in the case of an incremental. -# A partial is a partial full. +# Ignore the partial dump in the case of an incremental +# or when the partial is too old. A partial is a partial full. # -if ( $type ne "full" ) { +if ( $type ne "full" || time - $lastPartial > $Conf{PartialAgeMax} * 24*3600 ) { $partialNum = undef; $partialIdx = -1; } @@ -515,6 +522,8 @@ for my $shareName ( @$ShareNames ) { next; } + UserCommandRun("DumpPreShareCmd", $shareName); + if ( $Conf{XferMethod} eq "tar" ) { # # Use tar (eg: tar/ssh) as the transport program. @@ -528,6 +537,7 @@ for my $shareName ( @$ShareNames ) { my $errStr = BackupPC::Xfer::Rsync::errStr; print(LOG $bpc->timeStamp, "dump failed: $errStr\n"); print("dump failed: $errStr\n"); + UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd ); UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd ); exit(1); } @@ -647,6 +657,7 @@ for my $shareName ( @$ShareNames ) { sleep(1); kill($bpc->sigName2num("KILL"), @xferPid); } + UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd ); UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd ); exit(1); } @@ -760,6 +771,9 @@ for my $shareName ( @$ShareNames ) { next; } } + + UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd ); + $stat{xferOK} = 0 if ( $stat{hostError} || $stat{hostAbort} ); if ( !$stat{xferOK} ) { # @@ -1007,6 +1021,11 @@ sub BackupFailCleanup } } + # + # Don't keep partials if they are disabled + # + $keepPartial = 0 if ( $Conf{PartialAgeMax} < 0 ); + if ( !$keepPartial ) { # # No point in saving this dump; get rid of eveything. @@ -1094,8 +1113,26 @@ sub BackupExpire # Delete any old full backups, according to $Conf{FullKeepCntMin} # and $Conf{FullAgeMax}. # + # First make sure that $Conf{FullAgeMax} is at least bigger + # than $Conf{FullPeriod} * $Conf{FullKeepCnt}, including + # the exponential array case. + # + my $fullKeepCnt = $Conf{FullKeepCnt}; + $fullKeepCnt = [$fullKeepCnt] if ( ref($fullKeepCnt) ne "ARRAY" ); + my $fullAgeMax; + my $fullPeriod = int(0.5 + $Conf{FullPeriod}); + $fullPeriod = 7 if ( $fullPeriod <= 0 ); + for ( my $i = 0 ; $i < @$fullKeepCnt ; $i++ ) { + $fullAgeMax += $fullKeepCnt->[$i] * $fullPeriod; + $fullPeriod *= 2; + } + $fullAgeMax += $fullPeriod; # add some buffer + if ( $cntFull > $Conf{FullKeepCntMin} && $oldestFull > $Conf{FullAgeMax} + && $oldestFull > $fullAgeMax + && $Conf{FullKeepCntMin} > 0 + && $Conf{FullAgeMax} > 0 && (@Backups <= $firstFull + 1 || !$Backups[$firstFull + 1]{noFill}) ) { # @@ -1171,8 +1208,8 @@ sub BackupFullExpire # # Delete the full backup # - #printf("Deleting backup $i ($prevFull)\n"); - push(@delete, $i); + #print("Deleting backup $i ($prevFull)\n"); + unshift(@delete, $i); } else { $fullCnt++; while ( $fullKeepIdx < @$fullKeepCnt @@ -1313,6 +1350,11 @@ sub BackupRemove my($client, $Backups, $idx) = @_; my($Dir) = "$TopDir/pc/$client"; + if ( $Backups->[$idx]{num} eq "" ) { + print("BackupRemove: ignoring empty backup number for idx $idx\n"); + return; + } + $bpc->RmTreeDefer("$TopDir/trash", "$Dir/$Backups->[$idx]{num}"); unlink("$Dir/SmbLOG.$Backups->[$idx]{num}") @@ -1359,9 +1401,9 @@ sub pidHandler # sub UserCommandRun { - my($type) = @_; + my($cmdType, $sharename) = @_; - return if ( !defined($Conf{$type}) ); + return if ( !defined($Conf{$cmdType}) ); my $vars = { xfer => $xfer, client => $client, @@ -1379,9 +1421,15 @@ sub UserCommandRun xferOK => $stat{xferOK} || 0, hostError => $stat{hostError}, type => $type, + cmdType => $cmdType, }; - my $cmd = $bpc->cmdVarSubstitute($Conf{$type}, $vars); - $XferLOG->write(\"Executing $type: @$cmd\n"); + + if ($cmdType eq 'DumpPreShareCmd' || $cmdType eq 'DumpPostShareCmd') { + $vars->{share} = $sharename; + } + + my $cmd = $bpc->cmdVarSubstitute($Conf{$cmdType}, $vars); + $XferLOG->write(\"Executing $cmdType: @$cmd\n"); # # Run the user's command, dumping the stdout/stderr into the # Xfer log file. Also supply the optional $vars and %Conf in