# full or incremental backup needs to be run. If no backup is
# scheduled, or a ping to $client fails, then BackupPC_dump quits.
#
-# The backup is done using the selected XferMethod (smb, tar, rsync etc),
-# extracting the dump into $TopDir/pc/$client/new. The xfer output is
-# put into $TopDir/pc/$client/XferLOG.
+# The backup is done using the selected XferMethod (smb, tar, rsync,
+# backuppcd etc), extracting the dump into $TopDir/pc/$client/new.
+# The xfer output is put into $TopDir/pc/$client/XferLOG.
#
# If the dump succeeds (based on parsing the output of the XferMethod):
# - $TopDir/pc/$client/new is renamed to $TopDir/pc/$client/nnn, where
#
#========================================================================
#
-# Version 2.1.0beta2, released 23 May 2004.
+# Version 3.0.0alpha, released 23 Jan 2006.
#
# See http://backuppc.sourceforge.net.
#
use lib "/usr/local/BackupPC/lib";
use BackupPC::Lib;
use BackupPC::FileZIO;
+use BackupPC::Storage;
use BackupPC::Xfer::Smb;
use BackupPC::Xfer::Tar;
use BackupPC::Xfer::Rsync;
+use BackupPC::Xfer::BackupPCd;
use Socket;
use File::Path;
use File::Find;
}
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);
}
#
# 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});
$ShareNames = $Conf{TarShareName};
} elsif ( $Conf{XferMethod} eq "rsync" || $Conf{XferMethod} eq "rsyncd" ) {
$ShareNames = $Conf{RsyncShareName};
+} elsif ( $Conf{XferMethod} eq "backuppcd" ) {
+ $ShareNames = $Conf{BackupPCdShareName};
} else {
$ShareNames = $Conf{SmbShareName};
}
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);
+ }
+ } elsif ( $Conf{XferMethod} eq "backuppcd" ) {
+ #
+ # Use backuppcd as the transport program.
+ #
+ if ( !defined($xfer = BackupPC::Xfer::BackupPCd->new($bpc)) ) {
+ my $errStr = BackupPC::Xfer::BackupPCd::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} ) {
#
my($client) = @_;
my($Dir) = "$TopDir/pc/$client";
my(@Backups) = $bpc->BackupInfoRead($client);
- my($cntFull, $cntIncr, $firstFull, $firstIncr, $oldestIncr, $oldestFull);
+ my($cntFull, $cntIncr, $firstFull, $firstIncr, $oldestIncr,
+ $oldestFull, $changes);
if ( $Conf{FullKeepCnt} <= 0 ) {
print(LOG $bpc->timeStamp,
print(LOG $bpc->timeStamp,
"removing incr backup $Backups[$firstIncr]{num}\n");
BackupRemove($client, \@Backups, $firstIncr);
+ $changes++;
next;
}
#
my $fullKeepCnt = $Conf{FullKeepCnt};
$fullKeepCnt = [$fullKeepCnt] if ( ref($fullKeepCnt) ne "ARRAY" );
- my $oldestFull;
+ my $fullAgeMax;
my $fullPeriod = int(0.5 + $Conf{FullPeriod});
+ $fullPeriod = 7 if ( $fullPeriod <= 0 );
for ( my $i = 0 ; $i < @$fullKeepCnt ; $i++ ) {
- $oldestFull += $fullKeepCnt->[$i] * $fullPeriod;
+ $fullAgeMax += $fullKeepCnt->[$i] * $fullPeriod;
$fullPeriod *= 2;
}
- $oldestFull += $fullPeriod; # add some buffer
+ $fullAgeMax += $fullPeriod; # add some buffer
if ( $cntFull > $Conf{FullKeepCntMin}
&& $oldestFull > $Conf{FullAgeMax}
- && $oldestFull > $oldestFull
+ && $oldestFull > $fullAgeMax
&& $Conf{FullKeepCntMin} > 0
&& $Conf{FullAgeMax} > 0
&& (@Backups <= $firstFull + 1
print(LOG $bpc->timeStamp,
"removing old full backup $Backups[$firstFull]{num}\n");
BackupRemove($client, \@Backups, $firstFull);
+ $changes++;
next;
}
#
last if ( !BackupFullExpire($client, \@Backups) );
}
- $bpc->BackupInfoWrite($client, @Backups);
+ $bpc->BackupInfoWrite($client, @Backups) if ( $changes );
}
#
#
# 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 @Backups = $bpc->BackupInfoRead($client);
my $num = -1;
+ my $newFilesFH;
#
# Since we got a good backup we should remove any partial dumps
$Backups[$i]{noFill} = $type eq "incr" ? 1 : 0;
$Backups[$i]{level} = $type eq "incr" ? 1 : 0;
$Backups[$i]{mangle} = 1; # name mangling always on for v1.04+
+ $Backups[$i]{xferMethod} = $Conf{XferMethod};
+ $Backups[$i]{charset} = $Conf{ClientCharset};
+ #
+ # Save the main backups file
+ #
$bpc->BackupInfoWrite($client, @Backups);
+ #
+ # Save just this backup's info in case the main backups file
+ # gets corrupted
+ #
+ BackupPC::Storage->backupInfoWrite($Dir, $Backups[$i]{num},
+ $Backups[$i]);
unlink("$Dir/timeStamp.level0") if ( -f "$Dir/timeStamp.level0" );
foreach my $ext ( qw(bad bad.z) ) {
$file = "$f->{share}/$f->{file}";
}
next if ( !-f "$Dir/$Backups[$j]{num}/$file" );
- if ( !link("$Dir/$Backups[$j]{num}/$file",
- "$Dir/$num/$shareM/$fileM") ) {
- my $str = \"Unable to link $num/$f->{share}/$f->{file} to"
- . " $Backups[$j]{num}/$f->{share}/$f->{file}\n";
- $XferLOG->write(\$str);
+
+ my($exists, $digest, $origSize, $outSize, $errs)
+ = BackupPC::PoolWrite::LinkOrCopy(
+ $bpc,
+ "$Dir/$Backups[$j]{num}/$file",
+ $Backups[$j]{compress},
+ "$Dir/$num/$shareM/$fileM",
+ $Conf{CompressLevel});
+ if ( !$exists ) {
+ #
+ # the hard link failed, most likely because the target
+ # file has too many links. We have copied the file
+ # instead, so add this to the new file list.
+ #
+ if ( !defined($newFilesFH) ) {
+ my $str = "Appending to NewFileList for $shareM/$fileM\n";
+ $XferLOG->write(\$str);
+ open($newFilesFH, ">>", "$TopDir/pc/$client/NewFileList")
+ || die("can't open $TopDir/pc/$client/NewFileList");
+ binmode($newFilesFH);
+ }
+ if ( -f "$Dir/$num/$shareM/$fileM" ) {
+ print($newFilesFH "$digest $origSize $shareM/$fileM\n");
+ } else {
+ my $str = "Unable to link/copy $num/$f->{share}/$f->{file}"
+ . " to $Backups[$j]{num}/$f->{share}/$f->{file}\n";
+ $XferLOG->write(\$str);
+ }
} else {
my $str = "Bad file $num/$f->{share}/$f->{file} replaced"
. " by link to"
$XferLOG->write(\$str);
}
}
+ close($newFilesFH) if ( defined($newFilesFH) );
$XferLOG->close();
rename("$Dir/XferLOG$fileExt", "$Dir/XferLOG.$num$fileExt");
rename("$Dir/NewFileList", "$Dir/NewFileList.$num");
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