X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FXfer%2FRsync.pm;h=ff24cd5632db4d0227b6cf9574ebe3bfc681083d;hp=45f4f3b65ad828c2605c84a80dd1b9d3a1b7d78c;hb=f076585d3ff9dfe6de32292b897e293008efe74e;hpb=17dcbbebb871212f90b81bb97f8d1feb528bdc43 diff --git a/lib/BackupPC/Xfer/Rsync.pm b/lib/BackupPC/Xfer/Rsync.pm index 45f4f3b..ff24cd5 100644 --- a/lib/BackupPC/Xfer/Rsync.pm +++ b/lib/BackupPC/Xfer/Rsync.pm @@ -11,7 +11,7 @@ # Craig Barratt # # COPYRIGHT -# Copyright (C) 2002-2003 Craig Barratt +# Copyright (C) 2002-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.0, released 20 Jun 2004. +# Version 3.1.0, released 25 Nov 2007. # # See http://backuppc.sourceforge.net. # @@ -40,6 +40,8 @@ package BackupPC::Xfer::Rsync; use strict; use BackupPC::View; use BackupPC::Xfer::RsyncFileIO; +use Encode qw/from_to encode/; +use base qw(BackupPC::Xfer::Protocol); use vars qw( $RsyncLibOK $RsyncLibErr ); @@ -55,10 +57,10 @@ BEGIN { # # Note: also update configure.pl when this version number is changed! # - if ( $File::RsyncP::VERSION < 0.52 ) { + if ( $File::RsyncP::VERSION < 0.68 ) { $RsyncLibOK = 0; $RsyncLibErr = "File::RsyncP module version" - . " ($File::RsyncP::VERSION) too old: need 0.52"; + . " ($File::RsyncP::VERSION) too old: need >= 0.68"; } else { $RsyncLibOK = 1; } @@ -70,46 +72,8 @@ sub new my($class, $bpc, $args) = @_; return if ( !$RsyncLibOK ); - $args ||= {}; - my $t = bless { - bpc => $bpc, - conf => { $bpc->Conf }, - host => "", - hostIP => "", - shareName => "", - badFiles => [], - - # - # Various stats - # - byteCnt => 0, - fileCnt => 0, - xferErrCnt => 0, - xferBadShareCnt => 0, - xferBadFileCnt => 0, - xferOK => 0, - - # - # User's args - # - %$args, - }, $class; - - return $t; -} - -sub args -{ - my($t, $args) = @_; - - foreach my $arg ( keys(%$args) ) { - $t->{$arg} = $args->{$arg}; - } -} - -sub useTar -{ - return 0; + my $t = BackupPC::Xfer::Protocol->new($bpc, $args); + return bless($t, $class); } sub start @@ -130,6 +94,8 @@ sub start $rsyncArgs = $conf->{RsyncRestoreArgs}; my $remoteDir = "$t->{shareName}/$t->{pathHdrDest}"; $remoteDir =~ s{//+}{/}g; + from_to($remoteDir, "utf8", $conf->{ClientCharset}) + if ( $conf->{ClientCharset} ne "" ); $argList = ['--server', @$rsyncArgs, '.', $remoteDir]; $fioArgs = { client => $t->{bkupSrcHost}, @@ -197,9 +163,13 @@ sub start } } foreach my $file ( @inc ) { + $file = encode($conf->{ClientCharset}, $file) + if ( $conf->{ClientCharset} ne "" ); push(@fileList, "--include=$file"); } foreach my $file ( @exc ) { + $file = encode($conf->{ClientCharset}, $file) + if ( $conf->{ClientCharset} ne "" ); push(@fileList, "--exclude=$file"); } } @@ -209,19 +179,25 @@ sub start # # just append additional exclude lists onto the end # + $file = encode($conf->{ClientCharset}, $file) + if ( $conf->{ClientCharset} ne "" ); push(@fileList, "--exclude=$file"); } } if ( $t->{type} eq "full" ) { if ( $t->{partialNum} ) { $logMsg = "full backup started for directory $t->{shareName};" - . " updating partial $t->{partialNum}"; + . " updating partial #$t->{partialNum}"; } else { $logMsg = "full backup started for directory $t->{shareName}"; + if ( $t->{incrBaseBkupNum} ne "" ) { + $logMsg .= " (baseline backup #$t->{incrBaseBkupNum})"; + } } } else { - $incrDate = $bpc->timeStamp($t->{lastFull} - 3600, 1); - $logMsg = "incr backup started back to $incrDate for directory" + $incrDate = $bpc->timeStamp($t->{incrBaseTime}, 1); + $logMsg = "incr backup started back to $incrDate" + . " (backup #$t->{incrBaseBkupNum}) for directory" . " $t->{shareName}"; } @@ -237,15 +213,18 @@ sub start $rsyncArgs = [@$rsyncArgs, "--ignore-times"] if ( $t->{type} eq "full" ); $rsyncClientCmd = $conf->{RsyncClientCmd}; + my $shareNameSlash = $t->{shareNameSlash}; + from_to($shareNameSlash, "utf8", $conf->{ClientCharset}) + if ( $conf->{ClientCharset} ne "" ); $argList = ['--server', '--sender', @$rsyncArgs, - '.', $t->{shareNameSlash}]; + '.', $shareNameSlash]; eval { $argList = File::RsyncP->excludeStrip($argList); }; $fioArgs = { client => $t->{client}, share => $t->{shareName}, - viewNum => $t->{lastFullBkupNum}, + viewNum => $t->{incrBaseBkupNum}, partialNum => $t->{partialNum}, }; } @@ -263,6 +242,10 @@ sub start sshPath => $conf->{SshPath}, argList => $argList, }; + from_to($args->{shareName}, "utf8", $conf->{ClientCharset}) + if ( $conf->{ClientCharset} ne "" ); + from_to($args->{shareNameSlash}, "utf8", $conf->{ClientCharset}) + if ( $conf->{ClientCharset} ne "" ); $rsyncClientCmd = $bpc->cmdVarSubstitute($rsyncClientCmd, $args); # @@ -303,6 +286,7 @@ sub start pidHandler => sub { $t->{pidHandler}(@_); }, + clientCharset => $conf->{ClientCharset}, fio => BackupPC::Xfer::RsyncFileIO->new({ xfer => $t, bpc => $t->{bpc}, @@ -316,6 +300,7 @@ sub start $t->{XferLOG}->write(\$str); }, cacheCheckProb => $conf->{RsyncCsumCacheVerifyProb}, + clientCharset => $conf->{ClientCharset}, %$fioArgs, }), }); @@ -345,6 +330,11 @@ sub run $remoteDir = $t->{shareNameSlash}; $remoteDirDaemon = "."; } + from_to($remoteDir, "utf8", $conf->{ClientCharset}) + if ( $conf->{ClientCharset} ne "" ); + from_to($remoteDirDaemon, "utf8", $conf->{ClientCharset}) + if ( $conf->{ClientCharset} ne "" ); + if ( $t->{XferMethod} eq "rsync" ) { # # Run rsync command @@ -352,6 +342,8 @@ sub run my $str = "Running: " . $t->{bpc}->execCmd2ShellCmd(@{$t->{rsyncClientCmd}}) . "\n"; + from_to($str, $conf->{ClientCharset}, "utf8") + if ( $conf->{ClientCharset} ne "" ); $t->{XferLOG}->write(\$str); $rs->remoteStart($remoteSend, $remoteDir); } else { @@ -372,6 +364,8 @@ sub run # my $module = $t->{shareName}; $module = $t->{shareNameSlash} if ( $module =~ /\// ); + from_to($module, "utf8", $conf->{ClientCharset}) + if ( $conf->{ClientCharset} ne "" ); if ( defined(my $err = $rs->serverService($module, $conf->{RsyncdUserName}, $conf->{RsyncdPasswd}, @@ -384,7 +378,10 @@ sub run } $rs->serverStart($remoteSend, $remoteDirDaemon); } - my $error = $rs->go($t->{shareNameSlash}); + my $shareNameSlash = $t->{shareNameSlash}; + from_to($shareNameSlash, "utf8", $conf->{ClientCharset}) + if ( $conf->{ClientCharset} ne "" ); + my $error = $rs->go($shareNameSlash); $rs->serverClose(); # @@ -446,11 +443,6 @@ sub abort return 1; } -sub setSelectMask -{ - my($t, $FDreadRef) = @_; -} - sub errStr { my($t) = @_; @@ -466,39 +458,4 @@ sub xferPid return (); } -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;