* Added multi-level incrementals. Still needs testing.
[BackupPC.git] / bin / BackupPC_restore
index 5389e7d..ff9b413 100755 (executable)
@@ -29,7 +29,7 @@
 #
 #========================================================================
 #
-# Version 2.1.0, released 20 Jun 2004.
+# Version 3.0.0alpha, released 23 Jan 2006.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -43,6 +43,7 @@ use BackupPC::FileZIO;
 use BackupPC::Xfer::Smb;
 use BackupPC::Xfer::Tar;
 use BackupPC::Xfer::Rsync;
+use BackupPC::Xfer::BackupPCd;
 use Socket;
 
 use File::Path;
@@ -186,7 +187,10 @@ if ( (my $errMsg = CorrectHostCheck($hostIP, $host)) ) {
 #
 # Setup file extension for compression and open RestoreLOG output file
 #
-$Conf{CompressLevel} = 0 if ( !BackupPC::FileZIO->compOk );
+if ( $Conf{CompressLevel} && !BackupPC::FileZIO->compOk ) {
+    $stat{hostError} = "Compress:Zlib not found";
+    exit(RestoreCleanup($client));
+}
 my $fileExt = $Conf{CompressLevel} > 0 ? ".z" : "";
 my $RestoreLOG = BackupPC::FileZIO->open("$Dir/RestoreLOG$fileExt", 1,
                                      $Conf{CompressLevel});
@@ -204,6 +208,10 @@ local(*RH, *WH);
 # Run an optional pre-restore command
 #
 UserCommandRun("RestorePreUserCmd");
+if ( $? && $Conf{UserCmdCheckStatus} ) {
+    $stat{hostError} = "RestorePreUserCmd returned error status $?";
+    exit(RestoreCleanup($client));
+}
 $NeedPostCmd = 1;
 
 if ( $Conf{XferMethod} eq "tar" ) {
@@ -221,6 +229,16 @@ if ( $Conf{XferMethod} eq "tar" ) {
        $stat{hostError} = $errStr;
        exit(RestoreCleanup($client));
     }
+} elsif ( $Conf{XferMethod} eq "backuppcd" ) {
+    #
+    # Use backuppcd as the transport program.
+    #
+    if ( !defined($xfer = BackupPC::Xfer::BackupPCd->new($bpc)) ) {
+        my $errStr = BackupPC::Xfer::BackupPCd->errStr;
+       UserCommandRun("RestorePostUserCmd") if ( $NeedPostCmd );
+       $stat{hostError} = $errStr;
+       exit(RestoreCleanup($client));
+    }
 } else {
     #
     # Default is to use smbclient (smb) as the transport program.
@@ -527,7 +545,13 @@ sub RestoreCleanup
     #
     # Run an optional post-restore command
     #
-    UserCommandRun("RestorePostUserCmd") if ( $NeedPostCmd );
+    if ( $NeedPostCmd ) {
+        UserCommandRun("RestorePostUserCmd");
+        if ( $? && $Conf{UserCmdCheckStatus} ) {
+            $stat{hostError} = "RestorePostUserCmd returned error status $?";
+            $stat{xferOK} = 0;
+        }
+    }
 
     rename("$Dir/RestoreLOG$fileExt", "$Dir/RestoreLOG.$lastNum$fileExt");
     rename("$Dir/$reqFileName", "$Dir/RestoreInfo.$lastNum");