X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_dump;h=72f992c14432223f9462ac02343bea7fe10e118d;hp=62173e79f829eada33afba75c2d36cffa0be0858;hb=5b3e6091d542c2e7445d5dd511cdf6e20aec8b8d;hpb=e951f787a66c5bd9e9955c3f657a5b44289c0fe1 diff --git a/bin/BackupPC_dump b/bin/BackupPC_dump index 62173e7..72f992c 100755 --- a/bin/BackupPC_dump +++ b/bin/BackupPC_dump @@ -31,9 +31,9 @@ # 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 @@ -70,7 +70,7 @@ # #======================================================================== # -# Version 2.1.0, released 20 Jun 2004. +# Version 3.0.0alpha, released 23 Jan 2006. # # See http://backuppc.sourceforge.net. # @@ -81,9 +81,11 @@ no utf8; 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; @@ -348,7 +350,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); } @@ -434,7 +436,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}); @@ -492,6 +498,8 @@ if ( $Conf{XferMethod} eq "tar" ) { $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}; } @@ -518,6 +526,8 @@ for my $shareName ( @$ShareNames ) { next; } + UserCommandRun("DumpPreShareCmd", $shareName); + if ( $Conf{XferMethod} eq "tar" ) { # # Use tar (eg: tar/ssh) as the transport program. @@ -531,6 +541,19 @@ 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); + } + } 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); } @@ -650,6 +673,7 @@ for my $shareName ( @$ShareNames ) { sleep(1); kill($bpc->sigName2num("KILL"), @xferPid); } + UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd ); UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd ); exit(1); } @@ -763,6 +787,9 @@ for my $shareName ( @$ShareNames ) { next; } } + + UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd ); + $stat{xferOK} = 0 if ( $stat{hostError} || $stat{hostAbort} ); if ( !$stat{xferOK} ) { # @@ -1053,7 +1080,8 @@ sub BackupExpire 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, @@ -1095,6 +1123,7 @@ sub BackupExpire print(LOG $bpc->timeStamp, "removing incr backup $Backups[$firstIncr]{num}\n"); BackupRemove($client, \@Backups, $firstIncr); + $changes++; next; } @@ -1110,6 +1139,7 @@ sub BackupExpire $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; @@ -1133,6 +1163,7 @@ sub BackupExpire print(LOG $bpc->timeStamp, "removing old full backup $Backups[$firstFull]{num}\n"); BackupRemove($client, \@Backups, $firstFull); + $changes++; next; } @@ -1142,7 +1173,7 @@ sub BackupExpire # last if ( !BackupFullExpire($client, \@Backups) ); } - $bpc->BackupInfoWrite($client, @Backups); + $bpc->BackupInfoWrite($client, @Backups) if ( $changes ); } # @@ -1196,8 +1227,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 @@ -1236,6 +1267,7 @@ sub BackupSave { my @Backups = $bpc->BackupInfoRead($client); my $num = -1; + my $newFilesFH; # # Since we got a good backup we should remove any partial dumps @@ -1278,7 +1310,18 @@ sub BackupSave $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) ) { @@ -1304,11 +1347,34 @@ sub BackupSave $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" @@ -1323,6 +1389,7 @@ sub BackupSave $XferLOG->write(\$str); } } + close($newFilesFH) if ( defined($newFilesFH) ); $XferLOG->close(); rename("$Dir/XferLOG$fileExt", "$Dir/XferLOG.$num$fileExt"); rename("$Dir/NewFileList", "$Dir/NewFileList.$num"); @@ -1338,6 +1405,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}") @@ -1384,7 +1456,7 @@ sub pidHandler # sub UserCommandRun { - my($cmdType) = @_; + my($cmdType, $sharename) = @_; return if ( !defined($Conf{$cmdType}) ); my $vars = { @@ -1406,6 +1478,11 @@ sub UserCommandRun type => $type, cmdType => $cmdType, }; + + if ($cmdType eq 'DumpPreShareCmd' || $cmdType eq 'DumpPostShareCmd') { + $vars->{share} = $sharename; + } + my $cmd = $bpc->cmdVarSubstitute($Conf{$cmdType}, $vars); $XferLOG->write(\"Executing $cmdType: @$cmd\n"); #