- changed required File::RsyncP version to 0.50.
[BackupPC.git] / lib / BackupPC / Xfer / Rsync.pm
index ed60c87..d82f63c 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 2.0.0beta1, released 30 Mar 2003.
+# Version 2.1.0_CVS, released 8 Feb 2004.
 #
 # 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.30 ) {
+        if ( $File::RsyncP::VERSION < 0.50 ) {
             $RsyncLibOK = 0;
-            $RsyncLibErr = "File::RsyncP module version too old: need 0.30";
+            $RsyncLibErr = "File::RsyncP module version too old: need 0.50";
         } else {
             $RsyncLibOK = 1;
         }
@@ -176,8 +176,17 @@ sub start
                 # To make this easier we do all the includes first and all
                 # of the excludes at the end (hopefully they commute).
                 #
+                $file =~ s{/$}{};
                 $file = "/$file";
                 $file =~ s{//+}{/}g;
+               if ( $file eq "/" ) {
+                   #
+                   # This is a special case: if the user specifies
+                   # "/" then just include it and don't exclude "/*".
+                   #
+                    push(@inc, $file) if ( !$incDone{$file} );
+                   next;
+               }
                 my $f = "";
                 while ( $file =~ m{^/([^/]*)(.*)} ) {
                     my $elt = $1;
@@ -213,9 +222,14 @@ sub start
             }
         }
         if ( $t->{type} eq "full" ) {
-            $logMsg = "full backup started for directory $t->{shareName}";
+           if ( $t->{partialNum} ) {
+               $logMsg = "full backup started for directory $t->{shareName};"
+                       . " updating partial $t->{partialNum}";
+           } else {
+               $logMsg = "full backup started for directory $t->{shareName}";
+           }
         } else {
-            $incrDate = $bpc->timeStampISO($t->{lastFull} - 3600, 1);
+            $incrDate = $bpc->timeStamp($t->{lastFull} - 3600, 1);
             $logMsg = "incr backup started back to $incrDate for directory"
                     . " $t->{shareName}";
         }
@@ -235,9 +249,10 @@ sub start
         $argList = ['--server', '--sender', @$rsyncArgs,
                               '.', $t->{shareNameSlash}];
        $fioArgs = {
-           client  => $t->{client},
-           share   => $t->{shareName},
-           viewNum => $t->{lastFullBkupNum},
+           client     => $t->{client},
+           share      => $t->{shareName},
+           viewNum    => $t->{lastFullBkupNum},
+            partialNum => $t->{partialNum},
        };
     }
 
@@ -263,7 +278,7 @@ sub start
     #
     $t->{rsyncClientCmd} = $rsyncClientCmd;
     $t->{rs} = File::RsyncP->new({
-       logLevel     => $conf->{RsyncLogLevel},
+       logLevel     => $t->{logLevel} || $conf->{RsyncLogLevel},
        rsyncCmd     => sub {
                            $bpc->verbose(0);
                            $bpc->cmdExecOrEval($rsyncClientCmd, $args);
@@ -271,11 +286,26 @@ sub start
        rsyncCmdType => "full",
        rsyncArgs    => $rsyncArgs,
        timeout      => $conf->{ClientTimeout},
-       logHandler   => sub {
-                           my($str) = @_;
-                           $str .= "\n";
-                           $t->{XferLOG}->write(\$str);
-                       },
+       doPartial    => defined($t->{partialNum}) ? 1 : undef,
+       logHandler   =>
+                sub {
+                    my($str) = @_;
+                    $str .= "\n";
+                    $t->{XferLOG}->write(\$str);
+                    if ( $str =~ /^Remote\[1\]: read errors mapping "(.*)"/ ) {
+                        #
+                        # Files with read errors (eg: region locked files
+                        # on WinXX) are filled with 0 by rsync.  Remember
+                        # them and delete them later.
+                        #
+                        my $badFile = $1;
+                        $badFile =~ s/^\/+//;
+                        push(@{$t->{badFiles}}, {
+                                share => $t->{shareName},
+                                file  => $badFile
+                            });
+                    }
+                },
        pidHandler   => sub {
                            $t->{pidHandler}(@_);
                        },
@@ -284,7 +314,8 @@ sub start
                            bpc        => $t->{bpc},
                            conf       => $t->{conf},
                            backups    => $t->{backups},
-                           logLevel   => $conf->{RsyncLogLevel},
+                           logLevel   => $t->{logLevel}
+                                              || $conf->{RsyncLogLevel},
                            logHandler => sub {
                                              my($str) = @_;
                                              $str .= "\n";
@@ -411,6 +442,15 @@ sub run
     }
 }
 
+sub abort
+{
+    my($t, $reason) = @_;
+    my $rs = $t->{rs};
+
+    $rs->abort($reason);
+    return 1;
+}
+
 sub setSelectMask
 {
     my($t, $FDreadRef) = @_;