- fixed configure.pl and makeDist.
[BackupPC.git] / bin / BackupPC_restore
index 1186cac..8f78316 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/perl -T
+#!/bin/perl
 #============================================================= -*-perl-*-
 #
 # BackupPC_restore: Restore files to a client.
@@ -11,7 +11,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2001  Craig Barratt
+#   Copyright (C) 2001-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
 #
 #========================================================================
 #
-# Version 2.0.0beta3, released 1 Jun 2003.
+# Version 3.0.0alpha, released 23 Jan 2006.
 #
 # See http://backuppc.sourceforge.net.
 #
 #========================================================================
 
 use strict;
+no  utf8;
 use lib "/usr/local/BackupPC/lib";
 use BackupPC::Lib;
 use BackupPC::FileZIO;
 use BackupPC::Xfer::Smb;
 use BackupPC::Xfer::Tar;
 use BackupPC::Xfer::Rsync;
+use BackupPC::Xfer::BackupPCd;
 use Socket;
 
 use File::Path;
@@ -185,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});
@@ -220,6 +225,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.
@@ -263,6 +278,7 @@ my $xferArgs = {
     pipeWH       => *WH,
     XferLOG      => $RestoreLOG,
     XferMethod   => $Conf{XferMethod},
+    logLevel     => $Conf{XferLogLevel},
     bkupSrcHost  => $RestoreReq{hostSrc},
     bkupSrcShare => $RestoreReq{shareSrc},
     bkupSrcNum   => $RestoreReq{num},
@@ -320,6 +336,7 @@ if ( $useTar ) {
        $stat{hostError} = "Can't fork to run tar";
        exit(RestoreCleanup($client));
     }
+    binmode(TAR);
     if ( !$tarPid ) {
        #
        # This is the tarCreate child.  Clone STDERR to STDOUT,
@@ -330,6 +347,7 @@ if ( $useTar ) {
        open(STDERR, ">&STDOUT");
        close(STDOUT);
        open(STDOUT, ">&WH");
+       alarm(0);
        exec("$BinDir/BackupPC_tarCreate", @tarArgs);
        print(LOG $bpc->timeStamp, "can't exec $BinDir/BackupPC_tarCreate\n");
        # FIX: need to cleanup xfer
@@ -490,17 +508,17 @@ sub RestoreCleanup
        # kill off the tranfer program, first nicely then forcefully
        #
        if ( @xferPid ) {
-           kill(2, @xferPid);
+           kill($bpc->sigName2num("INT"), @xferPid);
            sleep(1);
-           kill(9, @xferPid);
+           kill($bpc->sigName2num("KILL"), @xferPid);
        }
        #
        # kill off the tar process, first nicely then forcefully
        #
        if ( $tarPid > 0 ) {
-           kill(2, $tarPid);
+           kill($bpc->sigName2num("INT"), $tarPid);
            sleep(1);
-           kill(9, $tarPid);
+           kill($bpc->sigName2num("KILL"), $tarPid);
        }
     }
 
@@ -607,11 +625,12 @@ sub pidHandler
 #
 sub UserCommandRun
 {
-    my($type) = @_;
+    my($cmdType) = @_;
 
-    return if ( !defined($Conf{$type}) );
+    return if ( !defined($Conf{$cmdType}) );
     my $vars = {
         xfer         => $xfer,
+        client       => $client,
         host         => $host,
         hostIP       => $hostIP,
         share        => $RestoreReq{shareDest},
@@ -622,8 +641,9 @@ sub UserCommandRun
        moreUsers    => $Hosts->{$client}{moreUsers},
         XferLOG      => $RestoreLOG,
         stat         => \%stat,
-        xferOK       => $stat{xferOK},
-       type         => $type,
+        xferOK       => $stat{xferOK} || 0,
+       hostError    => $stat{hostError},
+       type         => "restore",
        bkupSrcHost  => $RestoreReq{hostSrc},
        bkupSrcShare => $RestoreReq{shareSrc},
        bkupSrcNum   => $RestoreReq{num},
@@ -631,9 +651,10 @@ sub UserCommandRun
        pathHdrSrc   => $RestoreReq{pathHdrSrc},
        pathHdrDest  => $RestoreReq{pathHdrDest},
        fileList     => $RestoreReq{fileList},
+       cmdType      => $cmdType,
     };
-    my $cmd = $bpc->cmdVarSubstitute($Conf{$type}, $vars);
-    $RestoreLOG->write(\"Executing $type: @$cmd\n");
+    my $cmd = $bpc->cmdVarSubstitute($Conf{$cmdType}, $vars);
+    $RestoreLOG->write(\"Executing $cmdType: @$cmd\n");
     #
     # Run the user's command, dumping the stdout/stderr into the
     # Xfer log file.  Also supply the optional $vars and %Conf in