2 #============================================================= -*-perl-*-
4 # BackupPC_dump: Dump a single client.
8 # Usage: BackupPC_dump [-i] [-f] [-d] [-e] [-v] <client>
12 # -i Do an incremental dump, overriding any scheduling (but a full
13 # dump will be done if no dumps have yet succeeded)
15 # -f Do a full dump, overriding any scheduling.
17 # -d Host is a DHCP pool address, and the client argument
18 # just an IP address. We lookup the NetBios name from
21 # -e Just do an dump expiry check for the client. Don't do anything
22 # else. This is used periodically by BackupPC to make sure that
23 # dhcp hosts have correctly expired old backups. Without this,
24 # dhcp hosts that are no longer on the network will not expire
27 # -v verbose. for manual usage: prints failure reasons in more detail.
29 # BackupPC_dump is run periodically by BackupPC to backup $client.
30 # The file $TopDir/pc/$client/backups is read to decide whether a
31 # full or incremental backup needs to be run. If no backup is
32 # scheduled, or a ping to $client fails, then BackupPC_dump quits.
34 # The backup is done using the selected XferMethod (smb, tar, rsync,
35 # backuppcd etc), extracting the dump into $TopDir/pc/$client/new.
36 # The xfer output is put into $TopDir/pc/$client/XferLOG.
38 # If the dump succeeds (based on parsing the output of the XferMethod):
39 # - $TopDir/pc/$client/new is renamed to $TopDir/pc/$client/nnn, where
40 # nnn is the next sequential dump number.
41 # - $TopDir/pc/$client/XferLOG is renamed to $TopDir/pc/$client/XferLOG.nnn.
42 # - $TopDir/pc/$client/backups is updated.
45 # - $TopDir/pc/$client/new is moved to $TopDir/trash for later removal.
46 # - $TopDir/pc/$client/XferLOG is renamed to $TopDir/pc/$client/XferLOG.bad
49 # BackupPC_dump communicates to BackupPC via printing to STDOUT.
52 # Craig Barratt <cbarratt@users.sourceforge.net>
55 # Copyright (C) 2001-2003 Craig Barratt
57 # This program is free software; you can redistribute it and/or modify
58 # it under the terms of the GNU General Public License as published by
59 # the Free Software Foundation; either version 2 of the License, or
60 # (at your option) any later version.
62 # This program is distributed in the hope that it will be useful,
63 # but WITHOUT ANY WARRANTY; without even the implied warranty of
64 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65 # GNU General Public License for more details.
67 # You should have received a copy of the GNU General Public License
68 # along with this program; if not, write to the Free Software
69 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
71 #========================================================================
73 # Version 3.0.0alpha, released 23 Jan 2006.
75 # See http://backuppc.sourceforge.net.
77 #========================================================================
81 use lib "/usr/local/BackupPC/lib";
83 use BackupPC::FileZIO;
84 use BackupPC::Storage;
85 use BackupPC::Xfer::Smb;
86 use BackupPC::Xfer::Tar;
87 use BackupPC::Xfer::Rsync;
88 use BackupPC::Xfer::BackupPCd;
94 ###########################################################################
96 ###########################################################################
98 die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
99 my $TopDir = $bpc->TopDir();
100 my $BinDir = $bpc->BinDir();
101 my %Conf = $bpc->Conf();
110 if ( !getopts("defiv", \%opts) || @ARGV != 1 ) {
111 print("usage: $0 [-d] [-e] [-f] [-i] [-v] <client>\n");
114 if ( $ARGV[0] !~ /^([\w\.\s-]+)$/ ) {
115 print("$0: bad client name '$ARGV[0]'\n");
118 my $client = $1; # BackupPC's client name (might not be real host name)
119 my $hostIP; # this is the IP address
120 my $host; # this is the real host name
122 my($clientURI, $user);
124 $bpc->verbose(1) if ( $opts{v} );
128 # The client name $client is simply a DHCP address. We need to check
129 # if there is any machine at this address, and if so, get the actual
130 # host name via NetBios using nmblookup.
133 if ( $bpc->CheckHostAlive($hostIP) < 0 ) {
134 print(STDERR "Exiting because CheckHostAlive($hostIP) failed\n")
138 if ( $Conf{NmbLookupCmd} eq "" ) {
139 print(STDERR "Exiting because \$Conf{NmbLookupCmd} is empty\n")
143 ($client, $user) = $bpc->NetBiosInfoGet($hostIP);
144 if ( $client !~ /^([\w\.\s-]+)$/ ) {
145 print(STDERR "Exiting because NetBiosInfoGet($hostIP) returned"
146 . " '$client', an invalid host name\n") if ( $opts{v} );
149 $Hosts = $bpc->HostInfoRead($client);
152 $Hosts = $bpc->HostInfoRead($client);
154 if ( !defined($Hosts->{$client}) ) {
155 print(STDERR "Exiting because host $client does not exist in the"
156 . " hosts file\n") if ( $opts{v} );
160 my $Dir = "$TopDir/pc/$client";
165 # Re-read config file, so we can include the PC-specific config
167 $clientURI = $bpc->uriEsc($client);
168 if ( defined(my $error = $bpc->ConfigRead($client)) ) {
169 print("dump failed: Can't read PC's config file: $error\n");
172 %Conf = $bpc->Conf();
175 # Catch various signals
177 $SIG{INT} = \&catch_signal;
178 $SIG{ALRM} = \&catch_signal;
179 $SIG{TERM} = \&catch_signal;
180 $SIG{PIPE} = \&catch_signal;
181 $SIG{STOP} = \&catch_signal;
182 $SIG{TSTP} = \&catch_signal;
183 $SIG{TTIN} = \&catch_signal;
187 # Make sure we eventually timeout if there is no activity from
188 # the data transport program.
190 alarm($Conf{ClientTimeout});
192 mkpath($Dir, 0, 0777) if ( !-d $Dir );
193 if ( !-f "$Dir/LOCK" ) {
194 open(LOCK, ">", "$Dir/LOCK") && close(LOCK);
197 my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
198 my $logPath = sprintf("$Dir/LOG.%02d%04d", $mon + 1, $year + 1900);
200 if ( !-f $logPath ) {
202 # Compress and prune old log files
204 my $lastLog = $Conf{MaxOldPerPCLogFiles} - 1;
205 foreach my $file ( $bpc->sortedPCLogFiles($client) ) {
206 if ( $lastLog <= 0 ) {
210 next if ( $file =~ /\.z$/ || !$Conf{CompressLevel} );
211 BackupPC::FileZIO->compressCopy($file,
214 $Conf{CompressLevel}, 1);
219 open(LOG, ">>", $logPath);
220 select(LOG); $| = 1; select(STDOUT);
223 # For the -e option we just expire backups and quit
226 BackupExpire($client);
231 # For archive hosts we don't bother any further
233 if ($Conf{XferMethod} eq "archive" ) {
234 print(STDERR "Exiting because the XferMethod is set to archive\n")
241 # In the non-DHCP case, make sure the host can be looked up
242 # via NS, or otherwise find the IP address via NetBios.
244 if ( $Conf{ClientNameAlias} ne "" ) {
245 $host = $Conf{ClientNameAlias};
249 if ( !defined(gethostbyname($host)) ) {
251 # Ok, NS doesn't know about it. Maybe it is a NetBios name
254 print(STDERR "Name server doesn't know about $host; trying NetBios\n")
256 if ( !defined($hostIP = $bpc->NetBiosHostIPFind($host)) ) {
257 print(LOG $bpc->timeStamp, "Can't find host $host via netbios\n");
258 print("host not found\n");
266 ###########################################################################
267 # Figure out what to do and do it
268 ###########################################################################
271 # See if we should skip this host during a certain range
274 my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
276 print("Can't connect to server ($err)\n");
277 print(LOG $bpc->timeStamp, "Can't connect to server ($err)\n");
280 my $reply = $bpc->ServerMesg("status host($clientURI)");
281 $reply = $1 if ( $reply =~ /(.*)/s );
284 $bpc->ServerDisconnect();
287 # For DHCP tell BackupPC which host this is
290 if ( $StatusHost{activeJob} ) {
291 # oops, something is already running for this host
292 print(STDERR "Exiting because backup is already running for $client\n")
296 print("DHCP $hostIP $clientURI\n");
299 my($needLink, @Backups, $type);
300 my($incrBaseTime, $incrBaseBkupNum, $incrBaseLevel, $incrLevel);
301 my $lastFullTime = 0;
302 my $lastIncrTime = 0;
308 # Maintain backward compatibility with $Conf{FullPeriod} == -1 or -2
309 # meaning disable backups
311 $Conf{BackupsDisable} = -$Conf{FullPeriod}
312 if ( !$Conf{BackupsDisable} && $Conf{FullPeriod} < 0 );
314 if ( $Conf{BackupsDisable} == 1 && !$opts{f} && !$opts{i}
315 || $Conf{BackupsDisable} == 2 ) {
316 print(STDERR "Exiting because backups are disabled with"
317 . " \$Conf{BackupsDisable} = $Conf{BackupsDisable}\n") if ( $opts{v} );
319 # Tell BackupPC to ignore old failed backups on hosts that
320 # have backups disabled.
322 print("backups disabled\n")
323 if ( defined($StatusHost{errorTime})
324 && $StatusHost{reason} ne "Reason_backup_done"
325 && time - $StatusHost{errorTime} > 4 * 24 * 3600 );
326 NothingToDo($needLink);
329 if ( !$opts{i} && !$opts{f} && $Conf{BlackoutGoodCnt} >= 0
330 && $StatusHost{aliveCnt} >= $Conf{BlackoutGoodCnt} ) {
331 my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
332 my($currHours) = $hour + $min / 60 + $sec / 3600;
336 # Handle backward compatibility with original separate scalar
339 if ( defined($Conf{BlackoutHourBegin}) ) {
340 push(@{$Conf{BlackoutPeriods}},
342 hourBegin => $Conf{BlackoutHourBegin},
343 hourEnd => $Conf{BlackoutHourEnd},
344 weekDays => $Conf{BlackoutWeekDays},
348 foreach my $p ( @{$Conf{BlackoutPeriods}} ) {
350 # Allow blackout to span midnight (specified by BlackoutHourBegin
351 # being greater than BlackoutHourEnd)
353 next if ( ref($p->{weekDays}) ne "ARRAY"
354 || !defined($p->{hourBegin})
355 || !defined($p->{hourEnd})
357 if ( $p->{hourBegin} > $p->{hourEnd} ) {
358 $blackout = $p->{hourBegin} <= $currHours
359 || $currHours <= $p->{hourEnd};
360 if ( $currHours <= $p->{hourEnd} ) {
362 # This is after midnight, so decrement the weekday for the
363 # weekday check (eg: Monday 11pm-1am means Monday 2300 to
364 # Tuesday 0100, not Monday 2300-2400 plus Monday 0000-0100).
367 $wday += 7 if ( $wday < 0 );
370 $blackout = $p->{hourBegin} <= $currHours
371 && $currHours <= $p->{hourEnd};
373 if ( $blackout && grep($_ == $wday, @{$p->{weekDays}}) ) {
374 # print(LOG $bpc->timeStamp, "skipping because of blackout"
375 # . " (alive $StatusHost{aliveCnt} times)\n");
376 print(STDERR "Skipping $client because of blackout\n")
378 NothingToDo($needLink);
383 if ( !$opts{i} && !$opts{f} && $StatusHost{backoffTime} > time ) {
384 printf(LOG "%sskipping because of user requested delay (%.1f hours left)\n",
385 $bpc->timeStamp, ($StatusHost{backoffTime} - time) / 3600);
386 NothingToDo($needLink);
390 # Now see if there are any old backups we should delete
392 BackupExpire($client);
394 my(@lastIdxByLevel, $incrCntSinceFull);
397 # Read Backup information, and find times of the most recent full and
398 # incremental backups. Also figure out which backup we will use
399 # as a starting point for an incremental.
401 @Backups = $bpc->BackupInfoRead($client);
402 ## @Backups = sort( { $a->{startTime} <=> $b->{startTime} }, @Backups);
403 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
404 $needLink = 1 if ( $Backups[$i]{nFilesNew} eq ""
405 || -f "$Dir/NewFileList.$Backups[$i]{num}" );
406 if ( $Backups[$i]{type} eq "full" ) {
407 $incrCntSinceFull = 0;
408 $lastIdxByLevel[0] = $i;
409 if ( $lastFullTime < $Backups[$i]{startTime} ) {
410 $lastFullTime = $Backups[$i]{startTime};
412 } elsif ( $Backups[$i]{type} eq "incr" ) {
414 $lastIdxByLevel[$Backups[$i]{level}] = $i;
415 $lastIncrTime = $Backups[$i]{startTime}
416 if ( $lastIncrTime < $Backups[$i]{startTime} );
417 } elsif ( $Backups[$i]{type} eq "partial" ) {
419 $lastPartial = $Backups[$i]{startTime};
420 $partialNum = $Backups[$i]{num};
425 # Decide whether we do nothing, or a full or incremental backup.
429 || (!$opts{i} && (time - $lastFullTime > $Conf{FullPeriod} * 24*3600
430 && time - $lastIncrTime > $Conf{IncrPeriod} * 24*3600)) ) {
432 } elsif ( $opts{i} || (time - $lastIncrTime > $Conf{IncrPeriod} * 24*3600
433 && time - $lastFullTime > $Conf{IncrPeriod} * 24*3600) ) {
436 # For an incremental backup, figure out which level we should
437 # do and the index of the reference backup, which is the most
438 # recent backup at any lower level.
440 @{$Conf{IncrLevels}} = [$Conf{IncrLevels}]
441 unless ref($Conf{IncrLevels}) eq "ARRAY";
442 @{$Conf{IncrLevels}} = [1] if ( !@{$Conf{IncrLevels}} );
443 $incrCntSinceFull = $incrCntSinceFull % @{$Conf{IncrLevels}};
444 $incrLevel = $Conf{IncrLevels}[$incrCntSinceFull];
445 for ( my $i = 0 ; $i < $incrLevel ; $i++ ) {
446 my $idx = $lastIdxByLevel[$i];
447 next if ( !defined($idx) );
448 if ( !defined($incrBaseTime)
449 || $Backups[$idx]{startTime} < $incrBaseTime ) {
450 $incrBaseBkupNum = $Backups[$idx]{num};
451 $incrBaseLevel = $Backups[$idx]{level};
452 $incrBaseTime = $Backups[$idx]{startTime};
456 # Can't find any earlier lower-level backup! Shouldn't
457 # happen - just do full instead
459 $type = "full" if ( !defined($incrBaseBkupNum) || $incrLevel < 1 );
461 NothingToDo($needLink);
465 # Check if $host is alive
467 my $delay = $bpc->CheckHostAlive($hostIP);
469 print(LOG $bpc->timeStamp, "no ping response\n");
470 print("no ping response\n");
471 print("link $clientURI\n") if ( $needLink );
473 } elsif ( $delay > $Conf{PingMaxMsec} ) {
474 printf(LOG "%sping too slow: %.4gmsec\n", $bpc->timeStamp, $delay);
475 printf("ping too slow: %.4gmsec (threshold is %gmsec)\n",
476 $delay, $Conf{PingMaxMsec});
477 print("link $clientURI\n") if ( $needLink );
482 # Make sure it is really the machine we expect (only for fixed addresses,
483 # since we got the DHCP address above).
485 if ( !$opts{d} && (my $errMsg = CorrectHostCheck($hostIP, $host)) ) {
486 print(LOG $bpc->timeStamp, "dump failed: $errMsg\n");
487 print("dump failed: $errMsg\n");
489 } elsif ( $opts{d} ) {
490 print(LOG $bpc->timeStamp, "$host is dhcp $hostIP, user is $user\n");
494 # Get a clean directory $Dir/new
496 $bpc->RmTreeDefer("$TopDir/trash", "$Dir/new") if ( -d "$Dir/new" );
499 # Setup file extension for compression and open XferLOG output file
501 if ( $Conf{CompressLevel} && !BackupPC::FileZIO->compOk ) {
502 print(LOG $bpc->timeStamp, "dump failed: can't find Compress::Zlib\n");
503 print("dump failed: can't find Compress::Zlib\n");
506 my $fileExt = $Conf{CompressLevel} > 0 ? ".z" : "";
507 my $XferLOG = BackupPC::FileZIO->open("$Dir/XferLOG$fileExt", 1,
508 $Conf{CompressLevel});
509 if ( !defined($XferLOG) ) {
510 print(LOG $bpc->timeStamp, "dump failed: unable to open/create"
511 . " $Dir/XferLOG$fileExt\n");
512 print("dump failed: unable to open/create $Dir/XferLOG$fileExt\n");
517 # Ignore the partial dump in the case of an incremental
518 # or when the partial is too old. A partial is a partial full.
520 if ( $type ne "full" || time - $lastPartial > $Conf{PartialAgeMax} * 24*3600 ) {
526 # If this is a partial, copy the old XferLOG file
529 my($compress, $fileName);
530 if ( -f "$Dir/XferLOG.$partialNum.z" ) {
531 $fileName = "$Dir/XferLOG.$partialNum.z";
533 } elsif ( -f "$Dir/XferLOG.$partialNum" ) {
534 $fileName = "$Dir/XferLOG.$partialNum";
537 if ( my $oldLOG = BackupPC::FileZIO->open($fileName, 0, $compress) ) {
539 while ( $oldLOG->read(\$data, 65536) > 0 ) {
540 $XferLOG->write(\$data);
546 $XferLOG->writeTeeStderr(1) if ( $opts{v} );
547 unlink("$Dir/NewFileList") if ( -f "$Dir/NewFileList" );
549 my $startTime = time();
553 my $sizeExistComp = 0;
556 my($logMsg, %stat, $xfer, $ShareNames, $noFilesErr);
559 if ( $Conf{XferMethod} eq "tar" ) {
560 $ShareNames = $Conf{TarShareName};
561 } elsif ( $Conf{XferMethod} eq "rsync" || $Conf{XferMethod} eq "rsyncd" ) {
562 $ShareNames = $Conf{RsyncShareName};
563 } elsif ( $Conf{XferMethod} eq "backuppcd" ) {
564 $ShareNames = $Conf{BackupPCdShareName};
566 $ShareNames = $Conf{SmbShareName};
569 $ShareNames = [ $ShareNames ] unless ref($ShareNames) eq "ARRAY";
572 # Run an optional pre-dump command
574 UserCommandRun("DumpPreUserCmd");
575 if ( $? && $Conf{UserCmdCheckStatus} ) {
576 print(LOG $bpc->timeStamp,
577 "DumpPreUserCmd returned error status $?... exiting\n");
578 print("dump failed: DumpPreUserCmd returned error status $?\n");
584 # Now backup each of the shares
586 for my $shareName ( @$ShareNames ) {
589 $stat{xferOK} = $stat{hostAbort} = undef;
590 $stat{hostError} = $stat{lastOutputLine} = undef;
591 if ( -d "$Dir/new/$shareName" ) {
592 print(LOG $bpc->timeStamp,
593 "unexpected repeated share name $shareName skipped\n");
597 UserCommandRun("DumpPreShareCmd", $shareName);
598 if ( $? && $Conf{UserCmdCheckStatus} ) {
599 print(LOG $bpc->timeStamp,
600 "DumpPreShareCmd returned error status $?... exiting\n");
601 print("dump failed: DumpPreShareCmd returned error status $?\n");
602 UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd );
606 if ( $Conf{XferMethod} eq "tar" ) {
608 # Use tar (eg: tar/ssh) as the transport program.
610 $xfer = BackupPC::Xfer::Tar->new($bpc);
611 } elsif ( $Conf{XferMethod} eq "rsync" || $Conf{XferMethod} eq "rsyncd" ) {
613 # Use rsync as the transport program.
615 if ( !defined($xfer = BackupPC::Xfer::Rsync->new($bpc)) ) {
616 my $errStr = BackupPC::Xfer::Rsync::errStr;
617 print(LOG $bpc->timeStamp, "dump failed: $errStr\n");
618 print("dump failed: $errStr\n");
619 UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd );
620 UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd );
623 } elsif ( $Conf{XferMethod} eq "backuppcd" ) {
625 # Use backuppcd as the transport program.
627 if ( !defined($xfer = BackupPC::Xfer::BackupPCd->new($bpc)) ) {
628 my $errStr = BackupPC::Xfer::BackupPCd::errStr;
629 print(LOG $bpc->timeStamp, "dump failed: $errStr\n");
630 print("dump failed: $errStr\n");
631 UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd );
632 UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd );
637 # Default is to use smbclient (smb) as the transport program.
639 $xfer = BackupPC::Xfer::Smb->new($bpc);
642 my $useTar = $xfer->useTar;
646 # This xfer method outputs a tar format file, so we start a
647 # BackupPC_tarExtract to extract the data.
649 # Create a socketpair to connect the Xfer method to BackupPC_tarExtract
650 # WH is the write handle for writing, provided to the transport
651 # program, and RH is the other end of the socket for reading,
652 # provided to BackupPC_tarExtract.
654 if ( socketpair(RH, WH, AF_UNIX, SOCK_STREAM, PF_UNSPEC) ) {
655 shutdown(RH, 1); # no writing to this socket
656 shutdown(WH, 0); # no reading from this socket
657 setsockopt(RH, SOL_SOCKET, SO_RCVBUF, 8 * 65536);
658 setsockopt(WH, SOL_SOCKET, SO_SNDBUF, 8 * 65536);
661 # Default to pipe() if socketpair() doesn't work.
667 # fork a child for BackupPC_tarExtract. TAR is a file handle
668 # on which we (the parent) read the stdout & stderr from
669 # BackupPC_tarExtract.
671 if ( !defined($tarPid = open(TAR, "-|")) ) {
672 print(LOG $bpc->timeStamp, "can't fork to run tar\n");
673 print("can't fork to run tar\n");
681 # This is the tar child. Close the write end of the pipe,
682 # clone STDERR to STDOUT, clone STDIN from RH, and then
683 # exec BackupPC_tarExtract.
688 open(STDERR, ">&STDOUT");
692 exec("$BinDir/BackupPC_tarExtract", $client, $shareName,
693 $Conf{CompressLevel});
694 print(LOG $bpc->timeStamp,
695 "can't exec $BinDir/BackupPC_tarExtract\n");
698 } elsif ( !defined($newFilesFH) ) {
700 # We need to create the NewFileList output file
703 open(NEW_FILES, ">", "$TopDir/pc/$client/NewFileList")
704 || die("can't open $TopDir/pc/$client/NewFileList");
705 $newFilesFH = *NEW_FILES;
710 # Run the transport program
716 shareName => $shareName,
720 newFilesFH => $newFilesFH,
723 incrBaseTime => $incrBaseTime,
724 incrBaseBkupNum => $incrBaseBkupNum,
725 backups => \@Backups,
726 compress => $Conf{CompressLevel},
727 XferMethod => $Conf{XferMethod},
728 logLevel => $Conf{XferLogLevel},
729 pidHandler => \&pidHandler,
730 partialNum => $partialNum,
733 if ( !defined($logMsg = $xfer->start()) ) {
734 print(LOG $bpc->timeStamp, "xfer start failed: ", $xfer->errStr, "\n");
735 print("dump failed: ", $xfer->errStr, "\n");
736 print("link $clientURI\n") if ( $needLink );
738 # kill off the tar process, first nicely then forcefully
741 kill($bpc->sigName2num("INT"), $tarPid);
743 kill($bpc->sigName2num("KILL"), $tarPid);
746 kill($bpc->sigName2num("INT"), @xferPid);
748 kill($bpc->sigName2num("KILL"), @xferPid);
750 UserCommandRun("DumpPostShareCmd", $shareName) if ( $NeedPostCmd );
751 UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd );
755 @xferPid = $xfer->xferPid;
759 # The parent must close both handles on the pipe since the children
760 # are using these handles now.
765 print(LOG $bpc->timeStamp, $logMsg, "\n");
766 print("started $type dump, share=$shareName\n");
768 pidHandler(@xferPid);
772 # Parse the output of the transfer program and BackupPC_tarExtract
773 # while they run. Since we might be reading from two or more children
776 my($FDread, $tarOut, $mesg);
777 vec($FDread, fileno(TAR), 1) = 1 if ( $useTar );
778 $xfer->setSelectMask(\$FDread);
782 last if ( $FDread =~ /^\0*$/ );
783 select(my $rout = $FDread, undef, $ein, undef);
785 if ( vec($rout, fileno(TAR), 1) ) {
786 if ( sysread(TAR, $mesg, 8192) <= 0 ) {
787 vec($FDread, fileno(TAR), 1) = 0;
793 while ( $tarOut =~ /(.*?)[\n\r]+(.*)/s ) {
797 $XferLOG->write(\"$_\n");
799 $XferLOG->write(\"tarExtract: $_\n");
801 if ( /^BackupPC_tarExtact aborting \((.*)\)/ ) {
802 $stat{hostError} = $1;
804 if ( /^Done: (\d+) errors, (\d+) filesExist, (\d+) sizeExist, (\d+) sizeExistComp, (\d+) filesTotal, (\d+) sizeTotal/ ) {
808 $sizeExistComp += $4;
814 last if ( !$xfer->readOutput(\$FDread, $rout) );
815 while ( my $str = $xfer->logMsgGet ) {
816 print(LOG $bpc->timeStamp, "xfer: $str\n");
818 if ( $xfer->getStats->{fileCnt} == 1 ) {
820 # Make sure it is still the machine we expect. We do this while
821 # the transfer is running to avoid a potential race condition if
822 # the ip address was reassigned by dhcp just before we started
825 if ( my $errMsg = CorrectHostCheck($hostIP, $host) ) {
826 $stat{hostError} = $errMsg if ( $stat{hostError} eq "" );
833 # otherwise the xfer module does everything for us
835 my @results = $xfer->run();
836 $tarErrs += $results[0];
837 $nFilesExist += $results[1];
838 $sizeExist += $results[2];
839 $sizeExistComp += $results[3];
840 $nFilesTotal += $results[4];
841 $sizeTotal += $results[5];
845 # Merge the xfer status (need to accumulate counts)
847 my $newStat = $xfer->getStats;
848 if ( $newStat->{fileCnt} == 0 ) {
849 $noFilesErr ||= "No files dumped for share $shareName";
851 foreach my $k ( (keys(%stat), keys(%$newStat)) ) {
852 next if ( !defined($newStat->{$k}) );
853 if ( $k =~ /Cnt$/ ) {
854 $stat{$k} += $newStat->{$k};
855 delete($newStat->{$k});
858 if ( !defined($stat{$k}) ) {
859 $stat{$k} = $newStat->{$k};
860 delete($newStat->{$k});
865 if ( $NeedPostCmd ) {
866 UserCommandRun("DumpPostShareCmd", $shareName);
867 if ( $? && $Conf{UserCmdCheckStatus} ) {
868 print(LOG $bpc->timeStamp,
869 "DumpPostShareCmd returned error status $?... exiting\n");
870 $stat{hostError} = "DumpPostShareCmd returned error status $?";
874 $stat{xferOK} = 0 if ( $stat{hostError} || $stat{hostAbort} );
875 if ( !$stat{xferOK} ) {
877 # kill off the tranfer program, first nicely then forcefully
880 kill($bpc->sigName2num("INT"), @xferPid);
882 kill($bpc->sigName2num("KILL"), @xferPid);
885 # kill off the tar process, first nicely then forcefully
888 kill($bpc->sigName2num("INT"), $tarPid);
890 kill($bpc->sigName2num("KILL"), $tarPid);
893 # don't do any more shares on this host
900 # If this is a full, and any share had zero files then consider the dump bad
902 if ( $type eq "full" && $stat{hostError} eq ""
903 && length($noFilesErr) && $Conf{BackupZeroFilesIsFatal} ) {
904 $stat{hostError} = $noFilesErr;
908 $stat{xferOK} = 0 if ( $Abort );
911 # Do one last check to make sure it is still the machine we expect.
913 if ( $stat{xferOK} && (my $errMsg = CorrectHostCheck($hostIP, $host)) ) {
914 $stat{hostError} = $errMsg;
918 UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd );
919 if ( $? && $Conf{UserCmdCheckStatus} ) {
920 print(LOG $bpc->timeStamp,
921 "DumpPostUserCmd returned error status $?... exiting\n");
922 $stat{hostError} = "DumpPostUserCmd returned error status $?";
925 close($newFilesFH) if ( defined($newFilesFH) );
927 my $endTime = time();
930 # If the dump failed, clean up
932 if ( !$stat{xferOK} ) {
933 $stat{hostError} = $stat{lastOutputLine} if ( $stat{hostError} eq "" );
934 if ( $stat{hostError} ) {
935 print(LOG $bpc->timeStamp,
936 "Got fatal error during xfer ($stat{hostError})\n");
937 $XferLOG->write(\"Got fatal error during xfer ($stat{hostError})\n");
941 # wait a short while and see if the system is still alive
944 if ( $bpc->CheckHostAlive($hostIP) < 0 ) {
945 $stat{hostAbort} = 1;
947 if ( $stat{hostAbort} ) {
948 $stat{hostError} = "lost network connection during backup";
950 print(LOG $bpc->timeStamp, "Backup aborted ($stat{hostError})\n");
951 $XferLOG->write(\"Backup aborted ($stat{hostError})\n");
953 $XferLOG->write(\"Backup aborted by user signal\n");
957 # Close the log file and call BackupFailCleanup, which exits.
962 my $newNum = BackupSave();
964 my $otherCount = $stat{xferErrCnt} - $stat{xferBadFileCnt}
965 - $stat{xferBadShareCnt};
966 print(LOG $bpc->timeStamp,
967 "$type backup $newNum complete, $stat{fileCnt} files,"
968 . " $stat{byteCnt} bytes,"
969 . " $stat{xferErrCnt} xferErrs ($stat{xferBadFileCnt} bad files,"
970 . " $stat{xferBadShareCnt} bad shares, $otherCount other)\n");
972 BackupExpire($client);
974 print("$type backup complete\n");
976 ###########################################################################
978 ###########################################################################
984 print("nothing to do\n");
985 print("link $clientURI\n") if ( $needLink );
994 # The first time we receive a signal we try to gracefully
995 # abort the backup. This allows us to keep a partial dump
996 # with the in-progress file deleted and attribute caches
997 # flushed to disk etc.
999 if ( !length($SigName) ) {
1001 if ( $sigName eq "INT" ) {
1002 $reason = "aborted by user (signal=$sigName)";
1004 $reason = "aborted by signal=$sigName";
1008 # Parent logs a message
1010 print(LOG $bpc->timeStamp,
1011 "Aborting backup up after signal $sigName\n");
1014 # Tell xfer to abort
1016 $xfer->abort($reason);
1019 # Send ALRMs to BackupPC_tarExtract if we are using it
1021 if ( $tarPid > 0 ) {
1022 kill($bpc->sigName2num("ARLM"), $tarPid);
1026 # Schedule a 20 second timer in case the clean
1027 # abort doesn't complete
1032 # Children ignore anything other than ALRM and INT
1034 if ( $sigName ne "ALRM" && $sigName ne "INT" ) {
1039 # The child also tells xfer to abort
1041 $xfer->abort($reason);
1044 # Schedule a 15 second timer in case the clean
1045 # abort doesn't complete
1049 $SigName = $sigName;
1055 # This is a second signal: time to clean up.
1057 if ( $Pid != $$ && ($sigName eq "ALRM" || $sigName eq "INT") ) {
1059 # Children quit quietly on ALRM or INT
1065 # Ignore other signals in children
1067 return if ( $Pid != $$ );
1069 $SIG{$sigName} = 'IGNORE';
1070 UserCommandRun("DumpPostUserCmd") if ( $NeedPostCmd );
1071 $XferLOG->write(\"exiting after signal $sigName\n");
1073 kill($bpc->sigName2num("INT"), @xferPid);
1075 kill($bpc->sigName2num("KILL"), @xferPid);
1077 if ( $tarPid > 0 ) {
1078 kill($bpc->sigName2num("INT"), $tarPid);
1080 kill($bpc->sigName2num("KILL"), $tarPid);
1082 if ( $sigName eq "INT" ) {
1083 $stat{hostError} = "aborted by user (signal=$sigName)";
1085 $stat{hostError} = "received signal=$sigName";
1087 BackupFailCleanup();
1090 sub CheckForNewFiles
1092 if ( -f _ && $File::Find::name !~ /\/fattrib$/ ) {
1096 # No need to check entire tree
1098 $File::Find::prune = 1 if ( $nFilesTotal );
1102 sub BackupFailCleanup
1104 my $fileExt = $Conf{CompressLevel} > 0 ? ".z" : "";
1105 my $keepPartial = 0;
1108 # We keep this backup if it is a full and we actually backed
1111 if ( $type eq "full" ) {
1112 if ( $nFilesTotal == 0 && $xfer->getStats->{fileCnt} == 0 ) {
1114 # Xfer didn't report any files, but check in the new
1115 # directory just in case.
1117 find(\&CheckForNewFiles, "$Dir/new");
1118 $keepPartial = 1 if ( $nFilesTotal );
1121 # Xfer reported some files
1128 # Don't keep partials if they are disabled
1130 $keepPartial = 0 if ( $Conf{PartialAgeMax} < 0 );
1132 if ( !$keepPartial ) {
1134 # No point in saving this dump; get rid of eveything.
1137 unlink("$Dir/timeStamp.level0") if ( -f "$Dir/timeStamp.level0" );
1138 unlink("$Dir/SmbLOG.bad") if ( -f "$Dir/SmbLOG.bad" );
1139 unlink("$Dir/SmbLOG.bad$fileExt") if ( -f "$Dir/SmbLOG.bad$fileExt" );
1140 unlink("$Dir/XferLOG.bad") if ( -f "$Dir/XferLOG.bad" );
1141 unlink("$Dir/XferLOG.bad$fileExt") if ( -f "$Dir/XferLOG.bad$fileExt" );
1142 unlink("$Dir/NewFileList") if ( -f "$Dir/NewFileList" );
1143 rename("$Dir/XferLOG$fileExt", "$Dir/XferLOG.bad$fileExt");
1144 $bpc->RmTreeDefer("$TopDir/trash", "$Dir/new") if ( -d "$Dir/new" );
1145 print("dump failed: $stat{hostError}\n");
1147 print("link $clientURI\n") if ( $needLink );
1151 # Ok, now we should save this as a partial dump
1154 my $newNum = BackupSave();
1155 print("dump failed: $stat{hostError}\n");
1156 print("link $clientURI\n") if ( $needLink );
1157 print(LOG $bpc->timeStamp, "Saved partial dump $newNum\n");
1162 # Decide which old backups should be expired by moving them
1168 my($Dir) = "$TopDir/pc/$client";
1169 my(@Backups) = $bpc->BackupInfoRead($client);
1170 my($cntFull, $cntIncr, $firstFull, $firstIncr, $oldestIncr,
1171 $oldestFull, $changes);
1173 if ( $Conf{FullKeepCnt} <= 0 ) {
1174 print(LOG $bpc->timeStamp,
1175 "Invalid value for \$Conf{FullKeepCnt}=$Conf{FullKeepCnt}\n");
1177 "Invalid value for \$Conf{FullKeepCnt}=$Conf{FullKeepCnt}\n")
1182 $cntFull = $cntIncr = 0;
1183 $oldestIncr = $oldestFull = 0;
1184 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
1185 if ( $Backups[$i]{type} eq "full" ) {
1186 $firstFull = $i if ( $cntFull == 0 );
1188 } elsif ( $Backups[$i]{type} eq "incr" ) {
1189 $firstIncr = $i if ( $cntIncr == 0 );
1193 $oldestIncr = (time - $Backups[$firstIncr]{startTime}) / (24 * 3600)
1194 if ( $cntIncr > 0 );
1195 $oldestFull = (time - $Backups[$firstFull]{startTime}) / (24 * 3600)
1196 if ( $cntFull > 0 );
1199 # With multi-level incrementals, several of the following
1200 # incrementals might depend upon this one, so we have to
1201 # delete all of the them. Figure out if that is possible
1202 # by counting the number of consecutive incrementals that
1203 # are unfilled and have a level higher than this one.
1206 my $earliestIncr = $oldestIncr;
1208 for ( my $i = $firstIncr + 1 ; $i < @Backups ; $i++ ) {
1209 last if ( $Backups[$i]{level} <= $Backups[$firstIncr]{level}
1210 || !$Backups[$i]{noFill} );
1212 $earliestIncr = (time - $Backups[$i]{startTime}) / (24 * 3600);
1215 if ( $cntIncr >= $Conf{IncrKeepCnt} + $cntIncrDel
1216 || ($cntIncr >= $Conf{IncrKeepCntMin} + $cntIncrDel
1217 && $earliestIncr > $Conf{IncrAgeMax}) ) {
1219 # Only delete an incr backup if the Conf settings are satisfied
1220 # for all $cntIncrDel incrementals. Since BackupRemove() does
1221 # a splice() we need to do the deletes in the reverse order.
1223 for ( my $i = $firstIncr + $cntIncrDel - 1 ;
1224 $i >= $firstIncr ; $i-- ) {
1225 print(LOG $bpc->timeStamp,
1226 "removing incr backup $Backups[$i]{num}\n");
1227 BackupRemove($client, \@Backups, $i);
1234 # Delete any old full backups, according to $Conf{FullKeepCntMin}
1235 # and $Conf{FullAgeMax}.
1237 # First make sure that $Conf{FullAgeMax} is at least bigger
1238 # than $Conf{FullPeriod} * $Conf{FullKeepCnt}, including
1239 # the exponential array case.
1241 my $fullKeepCnt = $Conf{FullKeepCnt};
1242 $fullKeepCnt = [$fullKeepCnt] if ( ref($fullKeepCnt) ne "ARRAY" );
1244 my $fullPeriod = int(0.5 + $Conf{FullPeriod});
1245 $fullPeriod = 7 if ( $fullPeriod <= 0 );
1246 for ( my $i = 0 ; $i < @$fullKeepCnt ; $i++ ) {
1247 $fullAgeMax += $fullKeepCnt->[$i] * $fullPeriod;
1250 $fullAgeMax += $fullPeriod; # add some buffer
1252 if ( $cntFull > $Conf{FullKeepCntMin}
1253 && $oldestFull > $Conf{FullAgeMax}
1254 && $oldestFull > $fullAgeMax
1255 && $Conf{FullKeepCntMin} > 0
1256 && $Conf{FullAgeMax} > 0
1257 && (@Backups <= $firstFull + 1
1258 || !$Backups[$firstFull + 1]{noFill}) ) {
1260 # Only delete a full backup if the Conf settings are satisfied.
1261 # We also must make sure that either this backup is the most
1262 # recent one, or the next backup is filled.
1263 # (We can't deleted a full backup if the next backup is not
1266 print(LOG $bpc->timeStamp,
1267 "removing old full backup $Backups[$firstFull]{num}\n");
1268 BackupRemove($client, \@Backups, $firstFull);
1274 # Do new-style full backup expiry, which includes the the case
1275 # where $Conf{FullKeepCnt} is an array.
1277 last if ( !BackupFullExpire($client, \@Backups) );
1279 $bpc->BackupInfoWrite($client, @Backups) if ( $changes );
1283 # Handle full backup expiry, using exponential periods.
1285 sub BackupFullExpire
1287 my($client, $Backups) = @_;
1289 my $fullPeriod = $Conf{FullPeriod};
1290 my $origFullPeriod = $fullPeriod;
1291 my $fullKeepCnt = $Conf{FullKeepCnt};
1292 my $fullKeepIdx = 0;
1293 my(@delete, @fullList);
1296 # Don't delete anything if $Conf{FullPeriod} or $Conf{FullKeepCnt} are
1297 # not defined - possibly a corrupted config.pl file.
1299 return if ( !defined($Conf{FullPeriod}) || !defined($Conf{FullKeepCnt}) );
1302 # If regular backups are still disabled with $Conf{FullPeriod} < 0,
1303 # we still expire backups based on a typical FullPeriod value - weekly.
1305 $fullPeriod = 7 if ( $fullPeriod <= 0 );
1307 $fullKeepCnt = [$fullKeepCnt] if ( ref($fullKeepCnt) ne "ARRAY" );
1309 for ( my $i = 0 ; $i < @$Backups ; $i++ ) {
1310 next if ( $Backups->[$i]{type} ne "full" );
1311 push(@fullList, $i);
1313 for ( my $k = @fullList - 1 ; $k >= 0 ; $k-- ) {
1314 my $i = $fullList[$k];
1315 my $prevFull = $fullList[$k-1] if ( $k > 0 );
1317 # Don't delete any full that is followed by an unfilled backup,
1318 # since it is needed for restore.
1320 my $noDelete = $i + 1 < @$Backups ? $Backups->[$i+1]{noFill} : 0;
1323 ($fullKeepIdx >= @$fullKeepCnt
1326 && $Backups->[$i]{startTime} - $Backups->[$prevFull]{startTime}
1327 < ($fullPeriod - $origFullPeriod / 2) * 24 * 3600
1331 # Delete the full backup
1333 #print("Deleting backup $i ($prevFull)\n");
1334 unshift(@delete, $i);
1337 while ( $fullKeepIdx < @$fullKeepCnt
1338 && $fullCnt >= $fullKeepCnt->[$fullKeepIdx] ) {
1341 $fullPeriod = 2 * $fullPeriod;
1346 # Now actually delete the backups
1348 for ( my $i = @delete - 1 ; $i >= 0 ; $i-- ) {
1349 print(LOG $bpc->timeStamp,
1350 "removing full backup $Backups->[$delete[$i]]{num}\n");
1351 BackupRemove($client, $Backups, $delete[$i]);
1357 # Removes any partial backups
1359 sub BackupPartialRemove
1361 my($client, $Backups) = @_;
1363 for ( my $i = @$Backups - 1 ; $i >= 0 ; $i-- ) {
1364 next if ( $Backups->[$i]{type} ne "partial" );
1365 BackupRemove($client, $Backups, $i);
1371 my @Backups = $bpc->BackupInfoRead($client);
1376 # Since we got a good backup we should remove any partial dumps
1377 # (the new backup might also be a partial, but that's ok).
1379 BackupPartialRemove($client, \@Backups);
1382 # Number the new backup
1384 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
1385 $num = $Backups[$i]{num} if ( $num < $Backups[$i]{num} );
1388 $bpc->RmTreeDefer("$TopDir/trash", "$Dir/$num") if ( -d "$Dir/$num" );
1389 if ( !rename("$Dir/new", "$Dir/$num") ) {
1390 print(LOG $bpc->timeStamp, "Rename $Dir/new -> $Dir/$num failed\n");
1393 $needLink = 1 if ( -f "$Dir/NewFileList" );
1396 # Add the new backup information to the backup file
1399 $Backups[$i]{num} = $num;
1400 $Backups[$i]{type} = $type;
1401 $Backups[$i]{startTime} = $startTime;
1402 $Backups[$i]{endTime} = $endTime;
1403 $Backups[$i]{size} = $sizeTotal;
1404 $Backups[$i]{nFiles} = $nFilesTotal;
1405 $Backups[$i]{xferErrs} = $stat{xferErrCnt} || 0;
1406 $Backups[$i]{xferBadFile} = $stat{xferBadFileCnt} || 0;
1407 $Backups[$i]{xferBadShare} = $stat{xferBadShareCnt} || 0;
1408 $Backups[$i]{nFilesExist} = $nFilesExist;
1409 $Backups[$i]{sizeExist} = $sizeExist;
1410 $Backups[$i]{sizeExistComp} = $sizeExistComp;
1411 $Backups[$i]{tarErrs} = $tarErrs;
1412 $Backups[$i]{compress} = $Conf{CompressLevel};
1413 $Backups[$i]{noFill} = $type eq "incr" ? 1 : 0;
1414 $Backups[$i]{level} = $incrLevel;
1415 $Backups[$i]{mangle} = 1; # name mangling always on for v1.04+
1416 $Backups[$i]{xferMethod} = $Conf{XferMethod};
1417 $Backups[$i]{charset} = $Conf{ClientCharset};
1419 # Save the main backups file
1421 $bpc->BackupInfoWrite($client, @Backups);
1423 # Save just this backup's info in case the main backups file
1426 BackupPC::Storage->backupInfoWrite($Dir, $Backups[$i]{num},
1429 unlink("$Dir/timeStamp.level0") if ( -f "$Dir/timeStamp.level0" );
1430 foreach my $ext ( qw(bad bad.z) ) {
1431 next if ( !-f "$Dir/XferLOG.$ext" );
1432 unlink("$Dir/XferLOG.$ext.old") if ( -f "$Dir/XferLOG.$ext" );
1433 rename("$Dir/XferLOG.$ext", "$Dir/XferLOG.$ext.old");
1437 # Now remove the bad files, replacing them if possible with links to
1440 foreach my $f ( $xfer->getBadFiles ) {
1442 my $shareM = $bpc->fileNameEltMangle($f->{share});
1443 my $fileM = $bpc->fileNameMangle($f->{file});
1444 unlink("$Dir/$num/$shareM/$fileM");
1445 for ( $j = $i - 1 ; $j >= 0 ; $j-- ) {
1447 if ( $Backups[$j]{mangle} ) {
1448 $file = "$shareM/$fileM";
1450 $file = "$f->{share}/$f->{file}";
1452 next if ( !-f "$Dir/$Backups[$j]{num}/$file" );
1454 my($exists, $digest, $origSize, $outSize, $errs)
1455 = BackupPC::PoolWrite::LinkOrCopy(
1457 "$Dir/$Backups[$j]{num}/$file",
1458 $Backups[$j]{compress},
1459 "$Dir/$num/$shareM/$fileM",
1460 $Conf{CompressLevel});
1463 # the hard link failed, most likely because the target
1464 # file has too many links. We have copied the file
1465 # instead, so add this to the new file list.
1467 if ( !defined($newFilesFH) ) {
1468 my $str = "Appending to NewFileList for $shareM/$fileM\n";
1469 $XferLOG->write(\$str);
1470 open($newFilesFH, ">>", "$TopDir/pc/$client/NewFileList")
1471 || die("can't open $TopDir/pc/$client/NewFileList");
1472 binmode($newFilesFH);
1474 if ( -f "$Dir/$num/$shareM/$fileM" ) {
1475 print($newFilesFH "$digest $origSize $shareM/$fileM\n");
1477 my $str = "Unable to link/copy $num/$f->{share}/$f->{file}"
1478 . " to $Backups[$j]{num}/$f->{share}/$f->{file}\n";
1479 $XferLOG->write(\$str);
1482 my $str = "Bad file $num/$f->{share}/$f->{file} replaced"
1484 . " $Backups[$j]{num}/$f->{share}/$f->{file}\n";
1485 $XferLOG->write(\$str);
1490 my $str = "Removed bad file $num/$f->{share}/$f->{file}"
1491 . " (no older copy to link to)\n";
1492 $XferLOG->write(\$str);
1495 close($newFilesFH) if ( defined($newFilesFH) );
1497 rename("$Dir/XferLOG$fileExt", "$Dir/XferLOG.$num$fileExt");
1498 rename("$Dir/NewFileList", "$Dir/NewFileList.$num");
1504 # Removes a specific backup
1508 my($client, $Backups, $idx) = @_;
1509 my($Dir) = "$TopDir/pc/$client";
1511 if ( $Backups->[$idx]{num} eq "" ) {
1512 print("BackupRemove: ignoring empty backup number for idx $idx\n");
1516 $bpc->RmTreeDefer("$TopDir/trash",
1517 "$Dir/$Backups->[$idx]{num}");
1518 unlink("$Dir/SmbLOG.$Backups->[$idx]{num}")
1519 if ( -f "$Dir/SmbLOG.$Backups->[$idx]{num}" );
1520 unlink("$Dir/SmbLOG.$Backups->[$idx]{num}.z")
1521 if ( -f "$Dir/SmbLOG.$Backups->[$idx]{num}.z" );
1522 unlink("$Dir/XferLOG.$Backups->[$idx]{num}")
1523 if ( -f "$Dir/XferLOG.$Backups->[$idx]{num}" );
1524 unlink("$Dir/XferLOG.$Backups->[$idx]{num}.z")
1525 if ( -f "$Dir/XferLOG.$Backups->[$idx]{num}.z" );
1526 splice(@{$Backups}, $idx, 1);
1529 sub CorrectHostCheck
1531 my($hostIP, $host) = @_;
1532 return if ( $hostIP eq $host && !$Conf{FixedIPNetBiosNameCheck}
1533 || $Conf{NmbLookupCmd} eq "" );
1534 my($netBiosHost, $netBiosUser) = $bpc->NetBiosInfoGet($hostIP);
1535 return "host $host has mismatching netbios name $netBiosHost"
1536 if ( $netBiosHost ne $host );
1541 # The Xfer method might tell us from time to time about processes
1542 # it forks. We tell BackupPC about this (for status displays) and
1543 # keep track of the pids in case we cancel the backup
1548 @xferPid = grep(/./, @xferPid);
1549 return if ( !@xferPid && $tarPid < 0 );
1550 my @pids = @xferPid;
1551 push(@pids, $tarPid) if ( $tarPid > 0 );
1552 my $str = join(",", @pids);
1553 $XferLOG->write(\"Xfer PIDs are now $str\n") if ( defined($XferLOG) );
1554 print("xferPids $str\n");
1558 # Run an optional pre- or post-dump command
1562 my($cmdType, $sharename) = @_;
1564 return if ( !defined($Conf{$cmdType}) );
1570 user => $Hosts->{$client}{user},
1571 moreUsers => $Hosts->{$client}{moreUsers},
1572 share => $ShareNames->[0],
1573 shares => $ShareNames,
1574 XferMethod => $Conf{XferMethod},
1575 sshPath => $Conf{SshPath},
1577 XferLOG => $XferLOG,
1579 xferOK => $stat{xferOK} || 0,
1580 hostError => $stat{hostError},
1582 cmdType => $cmdType,
1585 if ($cmdType eq 'DumpPreShareCmd' || $cmdType eq 'DumpPostShareCmd') {
1586 $vars->{share} = $sharename;
1589 my $cmd = $bpc->cmdVarSubstitute($Conf{$cmdType}, $vars);
1590 $XferLOG->write(\"Executing $cmdType: @$cmd\n");
1592 # Run the user's command, dumping the stdout/stderr into the
1593 # Xfer log file. Also supply the optional $vars and %Conf in
1594 # case the command is really perl code instead of a shell
1597 $bpc->cmdSystemOrEval($cmd,
1599 $XferLOG->write(\$_[0]);