X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_dump;h=72f992c14432223f9462ac02343bea7fe10e118d;hp=8151cbd0df6dd4f178d7cc44a9962dbb5d90ad2a;hb=5b3e6091d542c2e7445d5dd511cdf6e20aec8b8d;hpb=17dcbbebb871212f90b81bb97f8d1feb528bdc43 diff --git a/bin/BackupPC_dump b/bin/BackupPC_dump index 8151cbd..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; @@ -496,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}; } @@ -541,6 +545,18 @@ for my $shareName ( @$ShareNames ) { 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); + } } else { # # Default is to use smbclient (smb) as the transport program. @@ -1064,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, @@ -1106,6 +1123,7 @@ sub BackupExpire print(LOG $bpc->timeStamp, "removing incr backup $Backups[$firstIncr]{num}\n"); BackupRemove($client, \@Backups, $firstIncr); + $changes++; next; } @@ -1145,6 +1163,7 @@ sub BackupExpire print(LOG $bpc->timeStamp, "removing old full backup $Backups[$firstFull]{num}\n"); BackupRemove($client, \@Backups, $firstFull); + $changes++; next; } @@ -1154,7 +1173,7 @@ sub BackupExpire # last if ( !BackupFullExpire($client, \@Backups) ); } - $bpc->BackupInfoWrite($client, @Backups); + $bpc->BackupInfoWrite($client, @Backups) if ( $changes ); } # @@ -1248,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 @@ -1290,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) ) { @@ -1316,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" @@ -1335,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");