begin search integration into version 3.2.0
[BackupPC.git] / bin / BackupPC_restore
1 #!/usr/bin/perl
2 #============================================================= -*-perl-*-
3 #
4 # BackupPC_restore: Restore files to a client.
5 #
6 # DESCRIPTION
7 #
8 #   Usage: BackupPC_restore <hostIP> <client> <reqFileName>
9 #
10 # AUTHOR
11 #   Craig Barratt  <cbarratt@users.sourceforge.net>
12 #
13 # COPYRIGHT
14 #   Copyright (C) 2001-2009  Craig Barratt
15 #
16 #   This program is free software; you can redistribute it and/or modify
17 #   it under the terms of the GNU General Public License as published by
18 #   the Free Software Foundation; either version 2 of the License, or
19 #   (at your option) any later version.
20 #
21 #   This program is distributed in the hope that it will be useful,
22 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
23 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 #   GNU General Public License for more details.
25 #
26 #   You should have received a copy of the GNU General Public License
27 #   along with this program; if not, write to the Free Software
28 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29 #
30 #========================================================================
31 #
32 # Version 3.2.0, released 31 Jul 2010.
33 #
34 # See http://backuppc.sourceforge.net.
35 #
36 #========================================================================
37
38 use strict;
39 no  utf8;
40 use lib "/usr/local/BackupPC/lib";
41 use BackupPC::Lib;
42 use BackupPC::FileZIO;
43 use BackupPC::Xfer;
44 use Socket;
45
46 use File::Path;
47 use Getopt::Std;
48
49 use vars qw( %RestoreReq );
50
51 ###########################################################################
52 # Initialize
53 ###########################################################################
54
55 die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
56 my $TopDir = $bpc->TopDir();
57 my $BinDir = $bpc->BinDir();
58 my %Conf   = $bpc->Conf();
59 my $NeedPostCmd;
60
61 my($hostIP, $host, $client, $reqFileName, %stat);
62
63 $bpc->ChildInit();
64
65 if ( @ARGV != 3 ) {
66     print("usage: $0 <hostIP> <client> <reqFileName>\n");
67     exit(1);
68 }
69 $hostIP = $1 if ( $ARGV[0] =~ /(.+)/ );
70 $client = $1 if ( $ARGV[1] =~ /(.+)/ );
71 if ( $ARGV[2] !~ /^([\w.]+)$/ ) {
72     print("$0: bad reqFileName (arg #3): $ARGV[2]\n");
73     exit(1);
74 }
75 $reqFileName = $1;
76
77 my $startTime = time();
78
79 my $Hosts = $bpc->HostInfoRead($client);
80
81 my $Dir     = "$TopDir/pc/$client";
82 my @xferPid = ();
83 my $tarPid  = -1;
84
85 #
86 # Catch various signals
87 #
88 $SIG{INT}  = \&catch_signal;
89 $SIG{ALRM} = \&catch_signal;
90 $SIG{TERM} = \&catch_signal;
91 $SIG{PIPE} = \&catch_signal;
92 $SIG{STOP} = \&catch_signal;
93 $SIG{TSTP} = \&catch_signal;
94 $SIG{TTIN} = \&catch_signal;
95 my $Pid = $$;
96
97 mkpath($Dir, 0, 0777) if ( !-d $Dir );
98 if ( !-f "$Dir/LOCK" ) {
99     open(LOCK, ">", "$Dir/LOCK") && close(LOCK);
100 }
101
102 my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
103 my $logPath = sprintf("$Dir/LOG.%02d%04d", $mon + 1, $year + 1900);
104
105 if ( !-f $logPath ) {
106     #
107     # Compress and prune old log files
108     #
109     my $lastLog = $Conf{MaxOldPerPCLogFiles} - 1;
110     foreach my $file ( $bpc->sortedPCLogFiles($client) ) {
111         if ( $lastLog <= 0 ) {
112             unlink($file);
113             next;
114         }
115         $lastLog--;
116         next if ( $file =~ /\.z$/ || !$Conf{CompressLevel} );
117         BackupPC::FileZIO->compressCopy($file,
118                                         "$file.z",
119                                         undef,
120                                         $Conf{CompressLevel}, 1);
121     }
122 }
123 open(LOG, ">>", $logPath);
124 select(LOG); $| = 1; select(STDOUT);
125
126 #
127 # Read the request file
128 #
129 if ( !(my $ret = do "$Dir/$reqFileName") ) {
130     my $err;
131     if ( $@ ) {
132         $err = "couldn't parse $Dir/$reqFileName: $@";
133     } elsif ( !defined($ret) ) {
134         $err = "couldn't do $Dir/$reqFileName: $!";
135     } else {
136         $err = "couldn't run $Dir/$reqFileName";
137     }
138     $stat{hostError} = $err;
139     exit(RestoreCleanup($client));
140 }
141
142 #
143 # Re-read config file, so we can include the PC-specific config
144 #
145 if ( defined(my $error = $bpc->ConfigRead($client)) ) {
146     $stat{hostError} = "Can't read PC's config file: $error";
147     exit(RestoreCleanup($client));
148 }
149 %Conf = $bpc->Conf();
150
151 #
152 # Make sure we eventually timeout if there is no activity from
153 # the data transport program.
154 #
155 alarm($Conf{ClientTimeout});
156
157 #
158 # See if the host name is aliased
159 #
160 if ( $Conf{ClientNameAlias} ne "" ) {
161     $host = $Conf{ClientNameAlias};
162 } else {
163     $host = $client;
164 }
165
166 #
167 # Find its IP address
168 #
169 if ( $hostIP !~ /\d+\.\d+\.\d+\.\d+/ ) {
170     if ( !defined(gethostbyname($host)) ) {
171         #
172         # Ok, NS doesn't know about it.  Maybe it is a NetBios name
173         # instead.
174         #
175         if ( !defined($hostIP = $bpc->NetBiosHostIPFind($host)) ) {
176             $stat{hostError} = "Can't find host $host";
177             exit(RestoreCleanup($client));
178         }
179     } else {
180         $hostIP = $host;
181     }
182 }
183
184 #
185 # Check if $host is alive
186 #
187 my $delay = $bpc->CheckHostAlive($hostIP);
188 if ( $delay < 0 ) {
189     $stat{hostError} = "no ping response from $host ($hostIP)";
190     exit(RestoreCleanup($client));
191 } elsif ( $delay > $Conf{PingMaxMsec} ) {
192     $stat{hostError} = sprintf("ping too slow: %.4gmsec (max is %gmsec)\n",
193                     $delay, $Conf{PingMaxMsec});
194     exit(RestoreCleanup($client));
195 }
196
197 #
198 # Make sure it is really the machine we expect
199 #
200 if ( (my $errMsg = CorrectHostCheck($hostIP, $host)) ) {
201     $stat{hostError} = $errMsg;
202     exit(RestoreCleanup($client));
203 }
204
205 #
206 # Setup file extension for compression and open RestoreLOG output file
207 #
208 if ( $Conf{CompressLevel} && !BackupPC::FileZIO->compOk ) {
209     $stat{hostError} = "Compress:Zlib not found";
210     exit(RestoreCleanup($client));
211 }
212 my $fileExt = $Conf{CompressLevel} > 0 ? ".z" : "";
213 my $RestoreLOG = BackupPC::FileZIO->open("$Dir/RestoreLOG$fileExt", 1,
214                                      $Conf{CompressLevel});
215 my $tarCreateFileCnt = 0;
216 my $tarCreateByteCnt = 0;
217 my $tarCreateDirCnt  = 0;
218 my $tarCreateErrCnt  = 1;       # assume not ok until we learn otherwise
219 my $tarCreateErr;
220 my($logMsg, $xfer);
221
222 $stat{xferOK} = $stat{hostAbort} = undef;
223 $stat{hostError} = $stat{lastOutputLine} = undef;
224 local(*RH, *WH);
225
226 #
227 # Run an optional pre-restore command
228 #
229 UserCommandRun("RestorePreUserCmd");
230 if ( $? && $Conf{UserCmdCheckStatus} ) {
231     $stat{hostError} = "RestorePreUserCmd returned error status $?";
232     exit(RestoreCleanup($client));
233 }
234 $NeedPostCmd = 1;
235
236 $xfer = BackupPC::Xfer::create($Conf{XferMethod}, $bpc);
237 if ( !defined($xfer) ) {
238     my $errStr = BackupPC::Xfer::errStr();
239     UserCommandRun("RestorePostUserCmd") if ( $NeedPostCmd );
240     $stat{hostError} = $errStr;
241     exit(RestoreCleanup($client));
242 }
243
244 my $useTar = $xfer->useTar;
245
246 if ( $useTar ) {
247     #
248     # Create a socketpair to connect BackupPC_tarCreate to the transport
249     # program (smbclient, tar, etc).
250     # WH is the write handle for writing, provided to BackupPC_tarCreate
251     # and RH is the other end of the pipe for reading provided to the
252     # transport program.
253     #
254     if ( socketpair(RH, WH, AF_UNIX, SOCK_STREAM, PF_UNSPEC) ) {
255         shutdown(RH, 1);    # no writing to this socket
256         shutdown(WH, 0);    # no reading from this socket
257         setsockopt(RH, SOL_SOCKET, SO_RCVBUF, 8 * 65536);
258         setsockopt(WH, SOL_SOCKET, SO_SNDBUF, 8 * 65536);
259     } else {
260         #
261         # Default to pipe() if socketpair() doesn't work.
262         #
263         pipe(RH, WH);
264     }
265 }
266
267 #
268 # Run the transport program, which reads from RH and extracts the data.
269 #
270 my @Backups = $bpc->BackupInfoRead($RestoreReq{hostSrc});
271 my $xferArgs = {
272     client       => $client,
273     host         => $host,
274     hostIP       => $hostIP,
275     type         => "restore",
276     shareName    => $RestoreReq{shareDest},
277     pipeRH       => *RH,
278     pipeWH       => *WH,
279     XferLOG      => $RestoreLOG,
280     XferMethod   => $Conf{XferMethod},
281     logLevel     => $Conf{XferLogLevel},
282     bkupSrcHost  => $RestoreReq{hostSrc},
283     bkupSrcShare => $RestoreReq{shareSrc},
284     bkupSrcNum   => $RestoreReq{num},
285     backups      => \@Backups,
286     pathHdrSrc   => $RestoreReq{pathHdrSrc},
287     pathHdrDest  => $RestoreReq{pathHdrDest},
288     fileList     => $RestoreReq{fileList},
289     pidHandler   => \&pidHandler,
290 };
291
292 $xfer->args($xferArgs);
293
294 if ( !defined($logMsg = $xfer->start()) ) {
295     UserCommandRun("RestorePostUserCmd") if ( $NeedPostCmd );
296     $stat{hostError} = "xfer start failed: ", $xfer->errStr;
297     exit(RestoreCleanup($client));
298 }
299
300 if ( $useTar ) {
301     #
302     # Now do the restore by running BackupPC_tarCreate
303     #
304     # The parent must close the read handle since the transport program
305     # is using it.
306     #
307     close(RH);
308
309     #
310     # fork a child for BackupPC_tarCreate.  TAR is a file handle
311     # on which we (the parent) read the stderr from BackupPC_tarCreate.
312     #
313     my @tarPathOpts;
314     if ( defined($RestoreReq{pathHdrDest})
315                 && $RestoreReq{pathHdrDest} ne $RestoreReq{pathHdrSrc} ) {
316         @tarPathOpts = ("-r", $RestoreReq{pathHdrSrc},
317                         "-p", $RestoreReq{pathHdrDest}
318                 );
319     }
320     my @tarArgs = (
321              "-h", $RestoreReq{hostSrc},
322              "-n", $RestoreReq{num},
323              "-s", $RestoreReq{shareSrc},
324              "-t",
325              @tarPathOpts,
326              @{$RestoreReq{fileList}},
327     );
328     my $runMsg = "Running: "
329                . $bpc->execCmd2ShellCmd("$BinDir/BackupPC_tarCreate", @tarArgs)
330                . "\n";
331     $RestoreLOG->write(\$runMsg);
332     if ( !defined($tarPid = open(TAR, "-|")) ) {
333         close(WH);
334         # FIX: need to cleanup xfer
335         UserCommandRun("RestorePostUserCmd") if ( $NeedPostCmd );
336         $stat{hostError} = "Can't fork to run tar";
337         exit(RestoreCleanup($client));
338     }
339     binmode(TAR);
340     if ( !$tarPid ) {
341         #
342         # This is the tarCreate child.  Clone STDERR to STDOUT,
343         # STDOUT to WH, and then exec BackupPC_tarCreate.
344         #
345         setpgrp 0,0;
346         close(STDERR);
347         open(STDERR, ">&STDOUT");
348         close(STDOUT);
349         open(STDOUT, ">&WH");
350         alarm(0);
351         exec("$BinDir/BackupPC_tarCreate", @tarArgs);
352         print(LOG $bpc->timeStamp, "can't exec $BinDir/BackupPC_tarCreate\n");
353         # FIX: need to cleanup xfer
354         exit(0);
355     }
356     #
357     # The parent must close the write handle since BackupPC_tarCreate
358     # is using it.
359     #
360     close(WH);
361
362     @xferPid = $xfer->xferPid;
363
364     print(LOG $bpc->timeStamp, $logMsg, "\n");
365     print("started_restore\n");
366
367     pidHandler(@xferPid);
368
369     #
370     # Parse the output of the transfer program and BackupPC_tarCreate
371     # while they run.  Since we are reading from two or more children
372     # we use a select.
373     #
374     my($FDread, $tarOut, $mesg);
375     vec($FDread, fileno(TAR), 1) = 1;
376     $xfer->setSelectMask(\$FDread);
377
378     SCAN: while ( 1 ) {
379         my $ein = $FDread;
380         last if ( $FDread =~ /^\0*$/ );
381         alarm($Conf{ClientTimeout});
382         select(my $rout = $FDread, undef, $ein, undef);
383         if ( vec($rout, fileno(TAR), 1) ) {
384             if ( sysread(TAR, $mesg, 8192) <= 0 ) {
385                 vec($FDread, fileno(TAR), 1) = 0;
386                 if ( !close(TAR) ) {
387                     $tarCreateErrCnt  = 1;
388                     $tarCreateErr = "BackupPC_tarCreate failed";
389                 }
390             } else {
391                 $tarOut .= $mesg;
392             }
393         }
394         while ( $tarOut =~ /(.*?)[\n\r]+(.*)/s ) {
395             $_ = $1;
396             $tarOut = $2;
397             $RestoreLOG->write(\"tarCreate: $_\n");
398             if ( /^Done: (\d+) files, (\d+) bytes, (\d+) dirs, (\d+) specials, (\d+) errors/ ) {
399                 $tarCreateFileCnt = $1;
400                 $tarCreateByteCnt = $2;
401                 $tarCreateDirCnt  = $3;
402                 $tarCreateErrCnt  = $5;
403             }
404         }
405         last if ( !$xfer->readOutput(\$FDread, $rout) );
406         while ( my $str = $xfer->logMsgGet ) {
407             print(LOG $bpc->timeStamp, "xfer: $str\n");
408         }
409         if ( $xfer->getStats->{fileCnt} == 1 ) {
410             #
411             # Make sure it is still the machine we expect.  We do this while
412             # the transfer is running to avoid a potential race condition if
413             # the ip address was reassigned by dhcp just before we started
414             # the transfer.
415             #
416             if ( my $errMsg = CorrectHostCheck($hostIP, $host) ) {
417                 $stat{hostError} = $errMsg;
418                 last SCAN;
419             }
420         }
421     }
422 } else {
423     #
424     # otherwise the xfer module does everything for us
425     #
426     print(LOG $bpc->timeStamp, $logMsg . "\n");
427     print("started_restore\n");
428     ($tarCreateFileCnt, $tarCreateByteCnt,
429         $tarCreateErrCnt, $tarCreateErr) = $xfer->run();
430 }
431 alarm(0);
432
433 #
434 # Merge the xfer status (need to accumulate counts)
435 #
436 my $newStat = $xfer->getStats;
437 foreach my $k ( (keys(%stat), keys(%$newStat)) ) {
438     next if ( !defined($newStat->{$k}) );
439     if ( $k =~ /Cnt$/ ) {
440         $stat{$k} += $newStat->{$k};
441         delete($newStat->{$k});
442         next;
443     }
444     if ( !defined($stat{$k}) ) {
445         $stat{$k} = $newStat->{$k};
446         delete($newStat->{$k});
447         next;
448     }
449 }
450
451 exit(RestoreCleanup($client));
452
453 ###########################################################################
454 # Subroutines
455 ###########################################################################
456
457 sub CorrectHostCheck
458 {
459     my($hostIP, $host) = @_;
460     return if ( $hostIP eq $host && !$Conf{FixedIPNetBiosNameCheck}
461                 || $Conf{NmbLookupCmd} eq "" );
462     my($netBiosHost, $netBiosUser) = $bpc->NetBiosInfoGet($hostIP);
463     return "host $host has mismatching netbios name $netBiosHost"
464             if ( lc($netBiosHost) ne lc(substr($host, 0, 15)) );
465     return;
466 }
467
468 sub catch_signal
469 {
470     my $signame = shift;
471
472     #
473     # Children quit quietly on ALRM
474     #
475     exit(1) if ( $Pid != $$ && $signame eq "ALRM" );
476
477     #
478     # Ignore signals in children
479     #
480     return if ( $Pid != $$ );
481
482     #
483     # Note: needs to be tested for each kind of XferMethod
484     #
485     print(LOG $bpc->timeStamp, "cleaning up after signal $signame\n");
486     $SIG{$signame} = 'IGNORE';
487     $RestoreLOG->write(\"exiting after signal $signame\n");
488     $stat{xferOK} = 0;
489     if ( $signame eq "INT" ) {
490         $stat{hostError} = "aborted by user (signal=$signame)";
491     } else {
492         $stat{hostError} = "aborted by signal=$signame";
493     }
494     exit(RestoreCleanup($client));
495 }
496
497 #
498 # Cleanup and update the restore status
499 #
500 sub RestoreCleanup
501 {
502     my($client) = @_;
503
504     $stat{xferOK} = 0 if ( $stat{hostError} || $stat{hostAbort}
505                         || $tarCreateErr );
506
507     if ( !$stat{xferOK} ) {
508         #
509         # kill off the tranfer program, first nicely then forcefully
510         #
511         if ( @xferPid ) {
512             kill($bpc->sigName2num("INT"), @xferPid);
513             sleep(1);
514             kill($bpc->sigName2num("KILL"), @xferPid);
515         }
516         #
517         # kill off the tar process, first nicely then forcefully
518         #
519         if ( $tarPid > 0 ) {
520             kill($bpc->sigName2num("INT"), $tarPid);
521             sleep(1);
522             kill($bpc->sigName2num("KILL"), $tarPid);
523         }
524     }
525
526     my $lastNum  = -1;
527     my @Restores;
528
529     #
530     # Do one last check to make sure it is still the machine we expect.
531     #
532     if ( $stat{xferOK} && (my $errMsg = CorrectHostCheck($hostIP, $host)) ) {
533         $stat{hostError} = $errMsg;
534         $stat{xferOK} = 0;
535     }
536     @Restores = $bpc->RestoreInfoRead($client);
537     for ( my $i = 0 ; $i < @Restores ; $i++ ) {
538         $lastNum = $Restores[$i]{num} if ( $lastNum < $Restores[$i]{num} );
539     }
540     $lastNum++;
541
542     #
543     # Run an optional post-restore command
544     #
545     if ( $NeedPostCmd ) {
546         UserCommandRun("RestorePostUserCmd");
547         if ( $? && $Conf{UserCmdCheckStatus} ) {
548             $stat{hostError} = "RestorePostUserCmd returned error status $?";
549             $stat{xferOK} = 0;
550         }
551     }
552
553     rename("$Dir/RestoreLOG$fileExt", "$Dir/RestoreLOG.$lastNum$fileExt");
554     rename("$Dir/$reqFileName", "$Dir/RestoreInfo.$lastNum");
555     my $endTime = time();
556
557     #
558     # If the restore failed, clean up
559     #
560     if ( !$stat{xferOK} ) {
561         #
562         # wait a short while and see if the system is still alive
563         #
564         $stat{hostError} ||= $tarCreateErr if ( $tarCreateErr ne "" );
565         $stat{hostError} = $stat{lastOutputLine} if ( $stat{hostError} eq "" );
566         sleep(2);
567         if ( $bpc->CheckHostAlive($hostIP) < 0 ) {
568             $stat{hostAbort} = 1;
569         }
570         if ( $stat{hostAbort} && $stat{hostError} eq "" ) {
571             $stat{hostError} = "lost network connection during restore";
572         }
573         $RestoreLOG->write(\"restore failed: $stat{hostError}\n")
574                                             if ( defined($RestoreLOG) );
575     }
576
577     $RestoreLOG->close() if ( defined($RestoreLOG) );
578
579     #
580     # Add the new restore information to the restore file
581     #
582     @Restores = $bpc->RestoreInfoRead($client);
583     my $i = @Restores;
584     $Restores[$i]{num}           = $lastNum;
585     $Restores[$i]{startTime}     = $startTime;
586     $Restores[$i]{endTime}       = $endTime;
587     $Restores[$i]{result}        = $stat{xferOK} ? "ok" : "failed";
588     $Restores[$i]{errorMsg}      = $stat{hostError};
589     $Restores[$i]{nFiles}        = $tarCreateFileCnt;
590     $Restores[$i]{size}          = $tarCreateByteCnt;
591     $Restores[$i]{tarCreateErrs} = $tarCreateErrCnt;
592     $Restores[$i]{xferErrs}      = $stat{xferErrCnt} || 0;
593
594     while ( @Restores > $Conf{RestoreInfoKeepCnt} ) {
595         my $num = $Restores[0]{num};
596         unlink("$Dir/RestoreLOG.$num.z");
597         unlink("$Dir/RestoreLOG.$num");
598         unlink("$Dir/RestoreInfo.$num");
599         shift(@Restores);
600     }
601     $bpc->RestoreInfoWrite($client, @Restores);
602
603     if ( !$stat{xferOK} ) {
604         print(LOG $bpc->timeStamp, "restore failed ($stat{hostError})\n");
605         print("restore failed: $stat{hostError}\n");
606         return 1;
607     } else {
608         $stat{xferErrCnt} ||= 0;
609         print(LOG $bpc->timeStamp, "restore $lastNum complete"
610                 . " ($tarCreateFileCnt files, $tarCreateByteCnt bytes,"
611                 . " $tarCreateDirCnt dirs, $stat{xferErrCnt} xferErrs)\n");
612         print("restore complete\n");
613         return;
614     }
615 }
616
617 #
618 # The Xfer method might tell us from time to time about processes
619 # it forks.  We tell BackupPC about this (for status displays) and
620 # keep track of the pids in case we cancel the backup
621 #
622 sub pidHandler
623 {
624     @xferPid = @_;
625     @xferPid = grep(/./, @xferPid);
626     return if ( !@xferPid && $tarPid < 0 );
627     my @pids = @xferPid;
628     push(@pids, $tarPid) if ( $tarPid > 0 );
629     my $str = join(",", @pids);
630     $RestoreLOG->write(\"Xfer PIDs are now $str\n") if ( defined($RestoreLOG) );
631     print("xferPids $str\n");
632 }
633
634 #
635 # Run an optional pre- or post-dump command
636 #
637 sub UserCommandRun
638 {
639     my($cmdType) = @_;
640
641     return if ( !defined($Conf{$cmdType}) );
642     my $vars = {
643         xfer         => $xfer,
644         client       => $client,
645         host         => $host,
646         hostIP       => $hostIP,
647         share        => $RestoreReq{shareDest},
648         XferMethod   => $Conf{XferMethod},
649         sshPath      => $Conf{SshPath},
650         LOG          => *LOG,
651         user         => $Hosts->{$client}{user},
652         moreUsers    => $Hosts->{$client}{moreUsers},
653         XferLOG      => $RestoreLOG,
654         stat         => \%stat,
655         xferOK       => $stat{xferOK} || 0,
656         hostError    => $stat{hostError},
657         type         => "restore",
658         bkupSrcHost  => $RestoreReq{hostSrc},
659         bkupSrcShare => $RestoreReq{shareSrc},
660         bkupSrcNum   => $RestoreReq{num},
661         backups      => \@Backups,
662         pathHdrSrc   => $RestoreReq{pathHdrSrc},
663         pathHdrDest  => $RestoreReq{pathHdrDest},
664         fileList     => $RestoreReq{fileList},
665         cmdType      => $cmdType,
666     };
667     my $cmd = $bpc->cmdVarSubstitute($Conf{$cmdType}, $vars);
668     $RestoreLOG->write(\"Executing $cmdType: @$cmd\n");
669     #
670     # Run the user's command, dumping the stdout/stderr into the
671     # Xfer log file.  Also supply the optional $vars and %Conf in
672     # case the command is really perl code instead of a shell
673     # command.
674     #
675     $bpc->cmdSystemOrEval($cmd,
676             sub {
677                 $RestoreLOG->write(\$_[0]);
678             },
679             $vars, \%Conf);
680 }