* Split BackupPC_Admin into a set of modules, one for each major action.
[BackupPC.git] / lib / BackupPC / Xfer / Rsync.pm
index b07c33b..8f8093b 100644 (file)
@@ -11,7 +11,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2002  Craig Barratt
+#   Copyright (C) 2002-2003  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 1.6.0_CVS, released 10 Dec 2002.
+# Version 2.1.0_CVS, released 3 Jul 2003.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -52,9 +52,9 @@ BEGIN {
         $RsyncLibOK = 0;
         $RsyncLibErr = "File::RsyncP module doesn't exist";
     } else {
-        if ( $File::RsyncP::VERSION < 0.20 ) {
+        if ( $File::RsyncP::VERSION < 0.41 ) {
             $RsyncLibOK = 0;
-            $RsyncLibErr = "File::RsyncP module version too old: need 0.20";
+            $RsyncLibErr = "File::RsyncP module version too old: need 0.41";
         } else {
             $RsyncLibOK = 1;
         }
@@ -119,7 +119,7 @@ sub start
     #
     # We add a slash to the share name we pass to rsync
     #
-    ($t->{shareNameSlash} = "$t->{shareName}/") =~ s{//+$}{};
+    ($t->{shareNameSlash} = "$t->{shareName}/") =~ s{//+$}{/};
 
     if ( $t->{type} eq "restore" ) {
         $rsyncClientCmd = $conf->{RsyncClientRestoreCmd};
@@ -128,7 +128,7 @@ sub start
        $remoteDir    =~ s{//+}{/}g;
         $argList = ['--server', @$rsyncArgs, '.', $remoteDir];
        $fioArgs = {
-           host     => $t->{bkupSrcHost},
+           client   => $t->{bkupSrcHost},
            share    => $t->{bkupSrcShare},
            viewNum  => $t->{bkupSrcNum},
            fileList => $t->{fileList},
@@ -228,13 +228,14 @@ sub start
         # transferred, even though it is a full dump.
         #
        $rsyncArgs = $conf->{RsyncArgs};
+       $rsyncArgs = [@$rsyncArgs, @fileList] if ( @fileList );
         $rsyncArgs = [@$rsyncArgs, "--ignore-times"]
                                     if ( $t->{type} eq "full" );
        $rsyncClientCmd = $conf->{RsyncClientCmd};
         $argList = ['--server', '--sender', @$rsyncArgs,
                               '.', $t->{shareNameSlash}];
        $fioArgs = {
-           host    => $t->{host},
+           client  => $t->{client},
            share   => $t->{shareName},
            viewNum => $t->{lastFullBkupNum},
        };
@@ -243,16 +244,17 @@ sub start
     #
     # Merge variables into $rsyncClientCmd
     #
-    $rsyncClientCmd = $bpc->cmdVarSubstitute($rsyncClientCmd,
-            {
-                host      => $t->{host},
-                hostIP    => $t->{hostIP},
-                shareName => $t->{shareName},
-                shareNameSlash => $t->{shareNameSlash},
-                rsyncPath => $conf->{RsyncClientPath},
-                sshPath   => $conf->{SshPath},
-                argList   => $argList,
-            });
+    my $args = {
+       host      => $t->{host},
+       hostIP    => $t->{hostIP},
+       client    => $t->{client},
+       shareName => $t->{shareName},
+       shareNameSlash => $t->{shareNameSlash},
+       rsyncPath => $conf->{RsyncClientPath},
+       sshPath   => $conf->{SshPath},
+       argList   => $argList,
+    };
+    $rsyncClientCmd = $bpc->cmdVarSubstitute($rsyncClientCmd, $args);
 
     #
     # Create the Rsync object, and tell it to use our own File::RsyncP::FileIO
@@ -263,22 +265,26 @@ sub start
     $t->{rs} = File::RsyncP->new({
        logLevel     => $conf->{RsyncLogLevel},
        rsyncCmd     => sub {
-                           $bpc->cmdExecOrEval($rsyncClientCmd);
+                           $bpc->verbose(0);
+                           $bpc->cmdExecOrEval($rsyncClientCmd, $args);
                        },
        rsyncCmdType => "full",
        rsyncArgs    => $rsyncArgs,
+       timeout      => $conf->{ClientTimeout},
        logHandler   => sub {
-                         my($str) = @_;
-                         $str .= "\n";
-                         $t->{XferLOG}->write(\$str);
+                           my($str) = @_;
+                           $str .= "\n";
+                           $t->{XferLOG}->write(\$str);
                        },
+       pidHandler   => sub {
+                           $t->{pidHandler}(@_);
+                       },
        fio          => BackupPC::Xfer::RsyncFileIO->new({
                            xfer       => $t,
                            bpc        => $t->{bpc},
                            conf       => $t->{conf},
                            backups    => $t->{backups},
                            logLevel   => $conf->{RsyncLogLevel},
-                           timeout    => $conf->{ClientTimeout},
                            logHandler => sub {
                                              my($str) = @_;
                                              $str .= "\n";
@@ -317,7 +323,10 @@ sub run
        #
        # Run rsync command
        #
-       $t->{XferLOG}->write(\"Running: @{$t->{rsyncClientCmd}}\n");
+       my $str = "Running: "
+               . $t->{bpc}->execCmd2ShellCmd(@{$t->{rsyncClientCmd}})
+               . "\n";
+       $t->{XferLOG}->write(\$str);
        $rs->remoteStart($remoteSend, $remoteDir);
     } else {
        #
@@ -326,6 +335,9 @@ sub run
        if ( defined(my $err = $rs->serverConnect($t->{hostIP},
                                             $conf->{RsyncdClientPort})) ) {
            $t->{hostError} = $err;
+           my $str = "Error connecting to rsync daemon at $t->{hostIP}"
+                   . ":$conf->{RsyncdClientPort}: $err\n";
+           $t->{XferLOG}->write(\$str);
            return;
        }
        #
@@ -338,6 +350,9 @@ sub run
                                              $conf->{RsyncdUserName},
                                              $conf->{RsyncdPasswd},
                                              $conf->{RsyncdAuthRequired})) ) {
+           my $str = "Error connecting to module $module at $t->{hostIP}"
+                   . ":$conf->{RsyncdClientPort}: $err\n";
+           $t->{XferLOG}->write(\$str);
            $t->{hostError} = $err;
            return;
        }
@@ -354,14 +369,19 @@ sub run
     #
     my $stats = $rs->statsFinal;
     if ( !defined($error) && defined($stats) ) {
-       $t->{xferOK}  = 1;
+       $t->{xferOK} = 1;
     } else {
-       $t->{xferOK}  = 0;
+       $t->{xferOK} = 0;
     }
-    $t->{byteCnt} = $stats->{childStats}{TotalFileSize}
-                 + $stats->{parentStats}{TotalFileSize};
-    $t->{fileCnt} = $stats->{childStats}{TotalFileCnt}
-                 + $stats->{parentStats}{TotalFileCnt};
+    $t->{xferErrCnt} = $stats->{remoteErrCnt}
+                    + $stats->{childStats}{errorCnt}
+                    + $stats->{parentStats}{errorCnt};
+    $t->{byteCnt}    = $stats->{childStats}{TotalFileSize}
+                    + $stats->{parentStats}{TotalFileSize};
+    $t->{fileCnt}    = $stats->{childStats}{TotalFileCnt}
+                    + $stats->{parentStats}{TotalFileCnt};
+    my $str = "Done: $t->{fileCnt} files, $t->{byteCnt} bytes\n";
+    $t->{XferLOG}->write(\$str);
     #
     # TODO: get error count, and call fio to get stats...
     #
@@ -408,7 +428,7 @@ sub xferPid
 {
     my($t) = @_;
 
-    return -1;
+    return ();
 }
 
 sub logMsg