X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FXfer%2FTar.pm;h=856d1b7e42e82783c0f3c8db6dc1d08c91ae2a01;hp=f8f22dce39da1ef3f1ccbcefa32d6f29488387a4;hb=b81d2da5e16975674f011e4833337ac0fa24e0ea;hpb=5729095faa3ef12dc5d4f02538c3650ac81912ef diff --git a/lib/BackupPC/Xfer/Tar.pm b/lib/BackupPC/Xfer/Tar.pm index f8f22dc..856d1b7 100644 --- a/lib/BackupPC/Xfer/Tar.pm +++ b/lib/BackupPC/Xfer/Tar.pm @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 2.1.0_CVS, released 3 Jul 2003. +# Version 3.0.0beta2, released 11 Nov 2006. # # See http://backuppc.sourceforge.net. # @@ -38,6 +38,7 @@ package BackupPC::Xfer::Tar; use strict; +use Encode qw/from_to encode/; sub new { @@ -92,34 +93,27 @@ sub start } else { # # Turn $conf->{BackupFilesOnly} and $conf->{BackupFilesExclude} - # into a hash of arrays of files + # into a hash of arrays of files, and $conf->{TarShareName} + # to an array # - $conf->{TarShareName} = [ $conf->{TarShareName} ] - unless ref($conf->{TarShareName}) eq "ARRAY"; - foreach my $param qw(BackupFilesOnly BackupFilesExclude) { - next if ( !defined($conf->{$param}) ); - if ( ref($conf->{$param}) eq "ARRAY" ) { - $conf->{$param} = { - $conf->{TarShareName}[0] => $conf->{$param} - }; - } elsif ( ref($conf->{$param}) eq "HASH" ) { - # do nothing - } else { - $conf->{$param} = { - $conf->{TarShareName}[0] => [ $conf->{$param} ] - }; - } - } + $bpc->backupFileConfFix($conf, "TarShareName"); + if ( defined($conf->{BackupFilesExclude}{$t->{shareName}}) ) { foreach my $file ( @{$conf->{BackupFilesExclude}{$t->{shareName}}} ) { - $file = ".$file" if ( $file =~ /^\// ); + $file = $2 if ( $file =~ m{^(\./+|/+)(.*)}s ); + $file = "./$file"; + $file = encode($conf->{ClientCharset}, $file) + if ( $conf->{ClientCharset} ne "" ); push(@fileList, "--exclude=$file"); } } if ( defined($conf->{BackupFilesOnly}{$t->{shareName}}) ) { foreach my $file ( @{$conf->{BackupFilesOnly}{$t->{shareName}}} ) { - $file = ".$file" if ( $file =~ /^\// ); + $file = $2 if ( $file =~ m{^(\./+|/+)(.*)}s ); + $file = "./$file"; + $file = encode($conf->{ClientCharset}, $file) + if ( $conf->{ClientCharset} ne "" ); push(@fileList, $file); } } else { @@ -135,9 +129,10 @@ sub start $args = $conf->{TarFullArgs}; $logMsg = "full backup started for directory $t->{shareName}"; } else { - $incrDate = $bpc->timeStamp($t->{lastFull} - 3600, 1); + $incrDate = $bpc->timeStamp($t->{incrBaseTime} - 3600, 1); $args = $conf->{TarIncrArgs}; - $logMsg = "incr backup started back to $incrDate for directory" + $logMsg = "incr backup started back to $incrDate" + . " (backup #$t->{incrBaseBkupNum}) for directory" . " $t->{shareName}"; } push(@$tarClientCmd, split(/ +/, $args)); @@ -155,6 +150,8 @@ sub start tarPath => $conf->{TarClientPath}, sshPath => $conf->{SshPath}, }; + from_to($args->{shareName}, "utf8", $conf->{ClientCharset}) + if ( $conf->{ClientCharset} ne "" ); $tarClientCmd = $bpc->cmdVarSubstitute($tarClientCmd, $args); if ( !defined($t->{xferPid} = open(TAR, "-|")) ) { $t->{_errStr} = "Can't fork to run tar"; @@ -189,12 +186,15 @@ sub start # # Run the tar command # + alarm(0); $bpc->cmdExecOrEval($tarClientCmd, $args); # should not be reached, but just in case... $t->{_errStr} = "Can't exec @$tarClientCmd"; return; } my $str = "Running: " . $bpc->execCmd2ShellCmd(@$tarClientCmd) . "\n"; + from_to($str, $conf->{ClientCharset}, "utf8") + if ( $conf->{ClientCharset} ne "" ); $t->{XferLOG}->write(\"Running: @$tarClientCmd\n"); alarm($conf->{ClientTimeout}); $t->{_errStr} = undef; @@ -218,21 +218,31 @@ sub readOutput $t->{tarOut} .= $mesg; } } + my $logFileThres = $t->{type} eq "restore" ? 1 : 2; while ( $t->{tarOut} =~ /(.*?)[\n\r]+(.*)/s ) { $_ = $1; $t->{tarOut} = $2; - $t->{XferLOG}->write(\"$_\n"); + from_to($_, $conf->{ClientCharset}, "utf8") + if ( $conf->{ClientCharset} ne "" ); # # refresh our inactivity alarm # - alarm($conf->{ClientTimeout}); + alarm($conf->{ClientTimeout}) if ( !$t->{abort} ); $t->{lastOutputLine} = $_ if ( !/^$/ ); if ( /^Total bytes written: / ) { + $t->{XferLOG}->write(\"$_\n") if ( $t->{logLevel} >= 1 ); $t->{xferOK} = 1; } elsif ( /^\./ ) { + $t->{XferLOG}->write(\"$_\n") if ( $t->{logLevel} >= $logFileThres ); $t->{fileCnt}++; } else { - $t->{xferErrCnt}++; + # + # Ignore annoying log message on incremental for tar 1.15.x + # + if ( !/: file is unchanged; not dumped$/ ) { + $t->{XferLOG}->write(\"$_\n") if ( $t->{logLevel} >= 0 ); + $t->{xferErrCnt}++; + } # # If tar encounters a minor error, it will exit with a non-zero # status. We still consider that ok. Remember if tar prints @@ -240,11 +250,34 @@ sub readOutput # $t->{tarBadExitOk} = 1 if ( $t->{xferOK} && /Error exit delayed from previous / ); + # + # Also remember files that had read errors + # + if ( /: \.\/(.*): Read error at byte / ) { + my $badFile = $1; + push(@{$t->{badFiles}}, { + share => $t->{shareName}, + file => $badFile + }); + } + } } return 1; } +sub abort +{ + my($t, $reason) = @_; + my @xferPid = $t->xferPid; + + $t->{abort} = 1; + $t->{abortReason} = $reason; + if ( @xferPid ) { + kill($t->{bpc}->sigName2num("INT"), @xferPid); + } +} + sub setSelectMask { my($t, $FDreadRef) = @_;