* BackupPC_trashClean now logs an error if it can't remove all the
[BackupPC.git] / bin / BackupPC_restore
index 7746a36..f63882b 100755 (executable)
@@ -29,7 +29,7 @@
 #
 #========================================================================
 #
-# Version 2.0.0_CVS, released 18 Jan 2003.
+# Version 2.0.0beta2, released 13 Apr 2003.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -76,10 +76,10 @@ $reqFileName = $1;
 
 my $startTime = time();
 
-my $Hosts = $bpc->HostInfoRead();
+my $Hosts = $bpc->HostInfoRead($client);
 
 my $Dir     = "$TopDir/pc/$client";
-my $xferPid = -1;
+my @xferPid = ();
 my $tarPid  = -1;
 
 #
@@ -96,6 +96,7 @@ if ( !-f "$Dir/LOCK" ) {
 open(LOG, ">>", "$Dir/LOG");
 select(LOG); $| = 1; select(STDOUT);
 
+
 #
 # Read the request file
 #
@@ -253,6 +254,7 @@ my $xferArgs = {
     pathHdrSrc   => $RestoreReq{pathHdrSrc},
     pathHdrDest  => $RestoreReq{pathHdrDest},
     fileList     => $RestoreReq{fileList},
+    pidHandler   => \&pidHandler,
 };
 
 $xfer->args($xferArgs);
@@ -323,9 +325,12 @@ if ( $useTar ) {
     #
     close(WH);
 
-    $xferPid = $xfer->xferPid;
-    print(LOG $bpc->timeStamp, $logMsg, " (tarPid=$tarPid, xferPid=$xferPid)\n");
-    print("started restore, tarPid=$tarPid, xferPid=$xferPid\n");
+    @xferPid = $xfer->xferPid;
+
+    print(LOG $bpc->timeStamp, $logMsg, "\n");
+    print("started_restore\n");
+
+    pidHandler(@xferPid);
 
     #
     # Parse the output of the transfer program and BackupPC_tarCreate
@@ -383,8 +388,8 @@ if ( $useTar ) {
     #
     # otherwise the xfer module does everything for us
     #
-    print(LOG $bpc->timeStamp, "Starting restore (tarPid=-1, xferPid=-1)\n");
-    print("started restore, tarPid=-1, xferPid=-1\n");
+    print(LOG $bpc->timeStamp, "Starting restore\n");
+    print("started_restore\n");
     ($tarCreateFileCnt, $tarCreateByteCnt,
        $tarCreateErrCnt, $tarCreateErr) = $xfer->run();
 }
@@ -417,7 +422,8 @@ exit(RestoreCleanup($client));
 sub CorrectHostCheck
 {
     my($hostIP, $host) = @_;
-    return if ( $hostIP eq $host && !$Conf{FixedIPNetBiosNameCheck} );
+    return if ( $hostIP eq $host && !$Conf{FixedIPNetBiosNameCheck}
+               || $Conf{NmbLookupCmd} eq "" );
     my($netBiosHost, $netBiosUser) = $bpc->NetBiosInfoGet($hostIP);
     return "host $host has mismatching netbios name $netBiosHost"
             if ( $netBiosHost ne $host );
@@ -432,17 +438,15 @@ sub catch_signal
     # Note: needs to be tested for each kind of XferMethod
     #
     print(LOG $bpc->timeStamp, "cleaning up after signal $signame\n");
-    if ( $xferPid > 0 ) {
-        if ( kill(2, $xferPid) <= 0 ) {
-            sleep(1);
-            kill(9, $xferPid);
-        }
+    if ( @xferPid ) {
+        kill(2, @xferPid);
+       sleep(1);
+       kill(9, @xferPid);
     }
     if ( $tarPid > 0 ) {
-        if ( kill(2, $tarPid) <= 0 ) {
-            sleep(1);
-            kill(9, $tarPid);
-        }
+        kill(2, $tarPid);
+       sleep(1);
+       kill(9, $tarPid);
     }
     $stat{xferOK} = 0;
     $stat{hostError} = "aborted by signal $signame";
@@ -462,15 +466,19 @@ sub RestoreCleanup
        #
        # kill off the tranfer program, first nicely then forcefully
        #
-       kill(2, $xferPid) if ( $xferPid > 0 );
-       sleep(1);
-       kill(9, $xferPid) if ( $xferPid > 0 );
+       if ( @xferPid ) {
+           kill(2, @xferPid);
+           sleep(1);
+           kill(9, @xferPid);
+       }
        #
        # kill off the tar process, first nicely then forcefully
        #
-       kill(2, $tarPid) if ( $tarPid > 0 );
-       sleep(1);
-       kill(9, $tarPid) if ( $tarPid > 0 );
+       if ( $tarPid > 0 ) {
+           kill(2, $tarPid);
+           sleep(1);
+           kill(9, $tarPid);
+       }
     }
 
     my $lastNum  = -1;
@@ -551,6 +559,23 @@ sub RestoreCleanup
     }
 }
 
+#
+# The Xfer method might tell us from time to time about processes
+# it forks.  We tell BackupPC about this (for status displays) and
+# keep track of the pids in case we cancel the backup
+#
+sub pidHandler
+{
+    @xferPid = @_;
+    @xferPid = grep(/./, @xferPid);
+    return if ( !@xferPid && $tarPid < 0 );
+    my @pids = @xferPid;
+    push(@pids, $tarPid) if ( $tarPid > 0 );
+    my $str = join(",", @pids);
+    $XferLOG->write(\"Xfer PIDs are now $str\n") if ( defined($XferLOG) );
+    print("xferPids $str\n");
+}
+
 #
 # Run an optional pre- or post-dump command
 #
@@ -565,7 +590,10 @@ sub UserCommandRun
         hostIP       => $hostIP,
         share        => $RestoreReq{shareDest},
         XferMethod   => $Conf{XferMethod},
+        sshPath      => $Conf{SshPath},
         LOG          => *LOG,
+       user         => $Hosts->{$client}{user},
+       moreUsers    => $Hosts->{$client}{moreUsers},
         XferLOG      => $RestoreLOG,
         stat         => \%stat,
         xferOK       => $stat{xferOK},