X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FXfer%2FSmb.pm;h=a92695a4670f3591c4e6f26f10d0ef354a530fb3;hp=688639729e02a59232d9edd2606d4b2f0f1fdf72;hb=f6fbcc3682d2bc9e7dfdc26e95bd5fcdb359496d;hpb=1a2fa2c2a1e0db12dc788216d9f3ba73301a131f diff --git a/lib/BackupPC/Xfer/Smb.pm b/lib/BackupPC/Xfer/Smb.pm index 6886397..a92695a 100644 --- a/lib/BackupPC/Xfer/Smb.pm +++ b/lib/BackupPC/Xfer/Smb.pm @@ -11,7 +11,7 @@ # Craig Barratt # # COPYRIGHT -# Copyright (C) 2001-2003 Craig Barratt +# Copyright (C) 2001-2007 Craig Barratt # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 2.1.0beta1, released 9 Apr 2004. +# Version 3.2.0beta0, released 5 April 2009. # # See http://backuppc.sourceforge.net. # @@ -38,35 +38,8 @@ package BackupPC::Xfer::Smb; use strict; - -sub new -{ - my($class, $bpc, $args) = @_; - - $args ||= {}; - my $t = bless { - bpc => $bpc, - conf => { $bpc->Conf }, - host => "", - hostIP => "", - shareName => "", - pipeRH => undef, - pipeWH => undef, - badFiles => [], - %$args, - }, $class; - - return $t; -} - -sub args -{ - my($t, $args) = @_; - - foreach my $arg ( keys(%$args) ) { - $t->{$arg} = $args->{$arg}; - } -} +use Encode qw/from_to encode/; +use base qw(BackupPC::Xfer::Protocol); sub useTar { @@ -103,33 +76,24 @@ 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->{SmbShareName} + # to an array # - $conf->{SmbShareName} = [ $conf->{SmbShareName} ] - unless ref($conf->{SmbShareName}) eq "ARRAY"; - foreach my $param qw(BackupFilesOnly BackupFilesExclude) { - next if ( !defined($conf->{$param}) ); - if ( ref($conf->{$param}) eq "ARRAY" ) { - $conf->{$param} = { - $conf->{SmbShareName}[0] => $conf->{$param} - }; - } elsif ( ref($conf->{$param}) eq "HASH" ) { - # do nothing - } else { - $conf->{$param} = { - $conf->{SmbShareName}[0] => [ $conf->{$param} ] - }; - } - } + $bpc->backupFileConfFix($conf, "SmbShareName"); + $t->{fileIncludeHash} = {}; if ( defined($conf->{BackupFilesOnly}{$t->{shareName}}) ) { foreach my $file ( @{$conf->{BackupFilesOnly}{$t->{shareName}}} ) { + $file = encode($conf->{ClientCharset}, $file) + if ( $conf->{ClientCharset} ne "" ); push(@fileList, $file); $t->{fileIncludeHash}{$file} = 1; } } elsif ( defined($conf->{BackupFilesExclude}{$t->{shareName}}) ) { foreach my $file ( @{$conf->{BackupFilesExclude}{$t->{shareName}}} ) { + $file = encode($conf->{ClientCharset}, $file) + if ( $conf->{ClientCharset} ne "" ); push(@fileList, $file); } # @@ -143,11 +107,13 @@ sub start } else { $timeStampFile = "$t->{outDir}/timeStamp.level0"; open(LEV0, ">", $timeStampFile) && close(LEV0); - utime($t->{lastFull} - 3600, $t->{lastFull} - 3600, $timeStampFile); + utime($t->{incrBaseTime} - 3600, $t->{incrBaseTime} - 3600, + $timeStampFile); $smbClientCmd = $conf->{SmbClientIncrCmd}; $logMsg = "incr backup started back to " - . $bpc->timeStamp($t->{lastFull} - 3600, 0) - . "for share $t->{shareName}"; + . $bpc->timeStamp($t->{incrBaseTime} - 3600, 0) + . " (backup #$t->{incrBaseBkupNum}) for share" + . " $t->{shareName}"; } } my $args = { @@ -162,6 +128,8 @@ sub start X_option => $X_option, timeStampFile => $timeStampFile, }; + from_to($args->{shareName}, "utf8", $conf->{ClientCharset}) + if ( $conf->{ClientCharset} ne "" ); $smbClientCmd = $bpc->cmdVarSubstitute($smbClientCmd, $args); if ( !defined($t->{xferPid} = open(SMB, "-|")) ) { @@ -204,6 +172,8 @@ sub start return; } my $str = "Running: " . $bpc->execCmd2ShellCmd(@$smbClientCmd) . "\n"; + from_to($str, $conf->{ClientCharset}, "utf8") + if ( $conf->{ClientCharset} ne "" ); $t->{XferLOG}->write(\$str); alarm($conf->{ClientTimeout}); $t->{_errStr} = undef; @@ -240,6 +210,9 @@ sub readOutput # alarm($conf->{ClientTimeout}) if ( !$t->{abort} ); $t->{lastOutputLine} = $_ if ( !/^$/ ); + + from_to($_, $conf->{ClientCharset}, "utf8") + if ( $conf->{ClientCharset} ne "" ); # # This section is highly dependent on the version of smbclient. # If you upgrade Samba, make sure that these regexp are still valid. @@ -274,6 +247,7 @@ sub readOutput || /^\s*Call timed out: server did not respond/i || /^\s*tree connect failed: ERRDOS - ERRnoaccess \(Access denied\.\)/ || /^\s*tree connect failed: NT_STATUS_BAD_NETWORK_NAME/ + || /^\s*NT_STATUS_INSUFF_SERVER_RESOURCES listing / ) { if ( $t->{hostError} eq "" ) { $t->{XferLOG}->write(\"This backup will fail because: $_\n"); @@ -282,6 +256,7 @@ sub readOutput $t->{XferLOG}->write(\"$_\n") if ( $t->{logLevel} >= 0 ); } elsif ( /^\s*NT_STATUS_ACCESS_DENIED listing (.*)/ || /^\s*ERRDOS - ERRnoaccess \(Access denied\.\) listing (.*)/ ) { + $t->{xferErrCnt}++; my $badDir = $1; $badDir =~ s{\\}{/}g; $badDir =~ s{/+}{/}g; @@ -347,14 +322,6 @@ sub readOutput return 1; } -sub abort -{ - my($t, $reason) = @_; - - $t->{abort} = 1; - $t->{abortReason} = $reason; -} - sub setSelectMask { my($t, $FDreadRef) = @_; @@ -362,53 +329,4 @@ sub setSelectMask vec($$FDreadRef, fileno($t->{pipeSMB}), 1) = 1; } -sub errStr -{ - my($t) = @_; - - return $t->{_errStr}; -} - -sub xferPid -{ - my($t) = @_; - - return ($t->{xferPid}); -} - -sub logMsg -{ - my($t, $msg) = @_; - - push(@{$t->{_logMsg}}, $msg); -} - -sub logMsgGet -{ - my($t) = @_; - - return shift(@{$t->{_logMsg}}); -} - -# -# Returns a hash ref giving various status information about -# the transfer. -# -sub getStats -{ - my($t) = @_; - - return { map { $_ => $t->{$_} } - qw(byteCnt fileCnt xferErrCnt xferBadShareCnt xferBadFileCnt - xferOK hostAbort hostError lastOutputLine) - }; -} - -sub getBadFiles -{ - my($t) = @_; - - return @{$t->{badFiles}}; -} - 1;