X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FXfer%2FSmb.pm;h=8fdbfea68c60d253a00515ada83af06e8225f67f;hp=06c1e4dd564d2abed75191c79fb1ffab9f9b8c5a;hb=75b84adc52496b24bd606333226aca5ce7424f65;hpb=e9453b7611be63303572ae443d5fb56b73364678 diff --git a/lib/BackupPC/Xfer/Smb.pm b/lib/BackupPC/Xfer/Smb.pm index 06c1e4d..8fdbfea 100644 --- a/lib/BackupPC/Xfer/Smb.pm +++ b/lib/BackupPC/Xfer/Smb.pm @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 1.6.0_CVS, released 10 Dec 2002. +# Version 2.0.0_CVS, released 3 Feb 2003. # # See http://backuppc.sourceforge.net. # @@ -78,8 +78,9 @@ sub start my($t) = @_; my $bpc = $t->{bpc}; my $conf = $t->{conf}; - my $I_option = $t->{hostIP} eq $t->{host} ? "" : " -I $t->{hostIP}"; - my($fileList, $optX, $smbClientCmd, $logMsg); + my $I_option = $t->{hostIP} eq $t->{host} ? [] : ['-I', $t->{hostIP}]; + my(@fileList, $X_option, $smbClientCmd, $logMsg); + my($timeStampFile); local(*SMB); # @@ -97,11 +98,7 @@ sub start return; } if ( $t->{type} eq "restore" ) { - $smbClientCmd = - "$conf->{SmbClientPath} '\\\\$t->{host}\\$t->{shareName}'" - . "$I_option -U '$conf->{SmbShareUserName}' -E -N -d 1" - . " $conf->{SmbClientArgs}" - . " -c 'tarmode full' -Tx -"; + $smbClientCmd = $conf->{SmbClientRestoreCmd}; $logMsg = "restore started for share $t->{shareName}"; } else { # @@ -126,43 +123,45 @@ sub start } if ( defined($conf->{BackupFilesOnly}{$t->{shareName}}) ) { foreach my $file ( @{$conf->{BackupFilesOnly}{$t->{shareName}}} ) { - $file =~ s/'/\\'/g; - $fileList .= "'$file' "; + push(@fileList, $file); } } elsif ( defined($conf->{BackupFilesExclude}{$t->{shareName}}) ) { foreach my $file ( @{$conf->{BackupFilesExclude}{$t->{shareName}}} ) { - $file =~ s/'/\\'/g; - $fileList .= "'$file' "; + push(@fileList, $file); } # # Allow simple wildcards in exclude list by specifying "r" option. # - $optX = "rX"; + $X_option = "rX"; } if ( $t->{type} eq "full" ) { - $smbClientCmd = - "$conf->{SmbClientPath} '\\\\$t->{host}\\$t->{shareName}'" - . "$I_option -U '$conf->{SmbShareUserName}' -E -N -d 1" - . " $conf->{SmbClientArgs}" - . " -c 'tarmode full'" - . " -Tc$optX - $fileList"; + $smbClientCmd = $conf->{SmbClientFullCmd}; $logMsg = "full backup started for share $t->{shareName}"; } else { - my $timeStampFile = "$t->{outDir}/timeStamp.level0"; - open(LEV0, ">$timeStampFile") && close(LEV0); + $timeStampFile = "$t->{outDir}/timeStamp.level0"; + open(LEV0, ">", $timeStampFile) && close(LEV0); utime($t->{lastFull} - 3600, $t->{lastFull} - 3600, $timeStampFile); - $smbClientCmd = - "$conf->{SmbClientPath} '\\\\$t->{host}\\$t->{shareName}'" - . "$I_option -U '$conf->{SmbShareUserName}' -E -N -d 1" - . " $conf->{SmbClientArgs}" - . " -c 'tarmode full'" - . " -TcN$optX $timeStampFile - $fileList"; + $smbClientCmd = $conf->{SmbClientIncrCmd}; $logMsg = "incr backup started back to " . $bpc->timeStamp($t->{lastFull} - 3600, 0) . "for share $t->{shareName}"; } } + my $args = { + smbClientPath => $conf->{SmbClientPath}, + host => $t->{host}, + hostIP => $t->{hostIP}, + client => $t->{client}, + shareName => $t->{shareName}, + userName => $conf->{SmbShareUserName}, + fileList => \@fileList, + I_option => $I_option, + X_option => $X_option, + timeStampFile => $timeStampFile, + }; + $smbClientCmd = $bpc->cmdVarSubstitute($smbClientCmd, $args); + if ( !defined($t->{xferPid} = open(SMB, "-|")) ) { $t->{_errStr} = "Can't fork to run smbclient"; return; @@ -194,15 +193,16 @@ sub start open(STDOUT, ">&$t->{pipeWH}"); } # - # exec smbclient. + # Run smbclient. # - exec($smbClientCmd); + $bpc->cmdExecOrEval($smbClientCmd, $args); # should not be reached, but just in case... $t->{_errStr} = "Can't exec $conf->{SmbClientPath}"; return; } - $t->{XferLOG}->write(\"Running: $smbClientCmd\n"); - alarm($conf->{SmbClientTimeout}); + my $str = "Running: " . $bpc->execCmd2ShellCmd(@$smbClientCmd) . "\n"; + $t->{XferLOG}->write(\$str); + alarm($conf->{ClientTimeout}); $t->{_errStr} = undef; return $logMsg; } @@ -228,7 +228,7 @@ sub readOutput # # refresh our inactivity alarm # - alarm($conf->{SmbClientTimeout}); + alarm($conf->{ClientTimeout}); $t->{lastOutputLine} = $_ if ( !/^$/ ); # # This section is highly dependent on the version of smbclient.