#
#========================================================================
#
-# Version 2.1.0beta0, released 20 Mar 2004.
+# Version 2.1.0, released 20 Jun 2004.
#
# See http://backuppc.sourceforge.net.
#
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);
}
}
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);
}
$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};
}
}
#
# 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});
}
#
-# 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;
}
next;
}
+ UserCommandRun("DumpPreShareCmd", $shareName);
+
if ( $Conf{XferMethod} eq "tar" ) {
#
# Use tar (eg: tar/ssh) as the transport program.
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);
}
sleep(1);
kill($bpc->sigName2num("KILL"), @xferPid);
}
+ UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd );
UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd );
exit(1);
}
next;
}
}
+
+ UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd );
+
$stat{xferOK} = 0 if ( $stat{hostError} || $stat{hostAbort} );
if ( !$stat{xferOK} ) {
#
}
}
+ #
+ # 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.
# 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}) ) {
#
#
# 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
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}")
#
sub UserCommandRun
{
- my($type) = @_;
+ my($cmdType, $sharename) = @_;
- return if ( !defined($Conf{$type}) );
+ return if ( !defined($Conf{$cmdType}) );
my $vars = {
xfer => $xfer,
client => $client,
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