added SearchHideShare regex to config
[BackupPC.git] / lib / BackupPC / Xfer / Rsync.pm
index ff24cd5..dd4f8ab 100644 (file)
@@ -11,7 +11,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2002-2007  Craig Barratt
+#   Copyright (C) 2002-2009  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 3.1.0, released 25 Nov 2007.
+# Version 3.2.0, released 31 Jul 2010.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -92,6 +92,17 @@ sub start
     if ( $t->{type} eq "restore" ) {
         $rsyncClientCmd = $conf->{RsyncClientRestoreCmd};
        $rsyncArgs = $conf->{RsyncRestoreArgs};
+
+        #
+        # Merge variables into $rsyncArgs
+        #
+        $rsyncArgs = $bpc->cmdVarSubstitute($rsyncArgs, {
+                            host      => $t->{host},
+                            hostIP    => $t->{hostIP},
+                            client    => $t->{client},
+                            confDir   => $conf->{ConfDir},
+                        });
+
        my $remoteDir = "$t->{shareName}/$t->{pathHdrDest}";
        $remoteDir    =~ s{//+}{/}g;
         from_to($remoteDir, "utf8", $conf->{ClientCharset})
@@ -209,6 +220,23 @@ sub start
         # transferred, even though it is a full dump.
         #
        $rsyncArgs = $conf->{RsyncArgs};
+
+        #
+        # Add any additional rsync args
+        #
+       $rsyncArgs = [@$rsyncArgs, @{$conf->{RsyncArgsExtra}}]
+                        if ( ref($conf->{RsyncArgsExtra}) eq 'ARRAY' );
+
+        #
+        # Merge variables into $rsyncArgs
+        #
+        $rsyncArgs = $bpc->cmdVarSubstitute($rsyncArgs, {
+                            host      => $t->{host},
+                            hostIP    => $t->{hostIP},
+                            client    => $t->{client},
+                            confDir   => $conf->{ConfDir},
+                        });
+
        $rsyncArgs = [@$rsyncArgs, @fileList] if ( @fileList );
         $rsyncArgs = [@$rsyncArgs, "--ignore-times"]
                                     if ( $t->{type} eq "full" );
@@ -286,6 +314,9 @@ sub start
        pidHandler   => sub {
                            $t->{pidHandler}(@_);
                        },
+       completionPercent => sub {
+                           $t->{completionPercent}(@_);
+                       },
         clientCharset => $conf->{ClientCharset},
        fio          => BackupPC::Xfer::RsyncFileIO->new({
                            xfer       => $t,
@@ -376,7 +407,26 @@ sub run
            $t->{hostError} = $err;
            return;
        }
+        
+        #
+        # This is a hack.  To avoid wide chars we encode the arguments
+        # to utf8 byte streams, then to the client's local charset.
+        # The second conversion should really go in File::RsyncP, since
+        # it shouldn't be applied to in-line include/exclude arguments.
+        #
+        for ( my $i = 0 ; $i < @{$rs->{rsyncArgs}} ; $i++ ) {
+            $rs->{rsyncArgs}[$i] = encode('utf8', $rs->{rsyncArgs}[$i]);
+            from_to($rs->{rsyncArgs}[$i], 'utf8', $conf->{ClientCharset})
+                                    if ( $conf->{ClientCharset} ne "" );
+        }
+    
+       ##my $str = "RsyncArgsBefore: " . join(" ", @{$rs->{rsyncArgs}}) . "\n";
+        ##$t->{XferLOG}->write(\$str);
+
        $rs->serverStart($remoteSend, $remoteDirDaemon);
+
+       ##$str = "RsyncArgsAfter: " . join(" ", @{$rs->{rsyncArgs}}) . "\n";
+        ##$t->{XferLOG}->write(\$str);
     }
     my $shareNameSlash = $t->{shareNameSlash};
     from_to($shareNameSlash, "utf8", $conf->{ClientCharset})