X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_archive;h=e1e99005bb8b8d02c9aa6ff9710369bf30b22a62;hp=3a3bea42c8d9a66e9dba7a42454bfef38ffc9043;hb=617af75f7419e95a9c3ea05b05cf21957acc331c;hpb=a7e968ce327855f2ba2624ca8517069a936c9b5b diff --git a/bin/BackupPC_archive b/bin/BackupPC_archive index 3a3bea4..e1e9900 100644 --- a/bin/BackupPC_archive +++ b/bin/BackupPC_archive @@ -1,4 +1,4 @@ -#!/bin/perl -T +#!/bin/perl #============================================================= -*-perl-*- # # BackupPC_archive: Archive files for an archive client. @@ -8,10 +8,10 @@ # Usage: BackupPC_archive # # AUTHOR -# Craig Barratt +# Josh Marshall # # COPYRIGHT -# Copyright (C) 2001-2003 Craig Barratt +# Copyright (C) 2001-2004 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 @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 2.1.0_CVS, released 3 Jul 2003. +# Version 3.0.0alpha, released 23 Jan 2006. # # See http://backuppc.sourceforge.net. # @@ -72,8 +72,6 @@ $reqFileName = $1; my $startTime = time(); -#my $Hosts = $bpc->HostInfoRead($client); - my $Dir = "$TopDir/pc/$client"; my @xferPid = (); @@ -113,6 +111,7 @@ if ( !(my $ret = do "$Dir/$reqFileName") ) { $stat{hostError} = $err; exit(ArchiveCleanup($client)); } + # # Re-read config file, so we can include the PC-specific config # @@ -140,7 +139,10 @@ if ( $Conf{ClientNameAlias} ne "" ) { # # Setup file extension for compression and open ArchiveLOG output file # -$Conf{CompressLevel} = 0 if ( !BackupPC::FileZIO->compOk ); +if ( $Conf{CompressLevel} && !BackupPC::FileZIO->compOk ) { + $stat{hostError} = "Compress::Zlib not found"; + exit(ArchiveCleanup($client)); +} my $fileExt = $Conf{CompressLevel} > 0 ? ".z" : ""; my $ArchiveLOG = BackupPC::FileZIO->open("$Dir/ArchiveLOG$fileExt", 1, $Conf{CompressLevel}); @@ -155,6 +157,10 @@ local(*RH, *WH); # Run an optional pre-archive command # UserCommandRun("ArchivePreUserCmd"); +if ( $? && $Conf{UserCmdCheckStatus} ) { + $stat{hostError} = "ArchivePreUserCmd returned error status $?"; + exit(ArchiveCleanup($client)); +} $NeedPostCmd = 1; $xfer = BackupPC::Xfer::Archive->new($bpc); @@ -191,7 +197,9 @@ if ( !defined($logMsg = $xfer->start()) ) { } print(LOG $bpc->timeStamp, "Starting archive\n"); +print("started_archive\n"); $xfer->run(); +$stat{xferOK} = 0 if ( defined($stat{hostError} = $xfer->errStr) ); alarm(0); exit(ArchiveCleanup($client)); @@ -240,12 +248,18 @@ sub ArchiveCleanup if ( !$stat{xferOK} ) { # - # kill off the tranfer program, first nicely then forcefully + # Kill off the tranfer program, first nicely then forcefully. + # We use negative PIDs to make sure all processes in each + # group get the signal. # if ( @xferPid ) { - kill(2, @xferPid); + foreach my $pid ( @xferPid ) { + kill($bpc->sigName2num("INT"), -$pid); + } sleep(1); - kill(9, @xferPid); + foreach my $pid ( @xferPid ) { + kill($bpc->sigName2num("KILL"), -$pid); + } } } @@ -261,7 +275,13 @@ sub ArchiveCleanup # # Run an optional post-archive command # - UserCommandRun("ArchivePostUserCmd") if ( $NeedPostCmd ); + if ( $NeedPostCmd ) { + UserCommandRun("ArchivePostUserCmd"); + if ( $? && $Conf{UserCmdCheckStatus} ) { + $stat{hostError} = "RestorePreUserCmd returned error status $?"; + $stat{xferOK} = 0; + } + } rename("$Dir/ArchiveLOG$fileExt", "$Dir/ArchiveLOG.$lastNum$fileExt"); rename("$Dir/$reqFileName", "$Dir/ArchiveInfo.$lastNum"); @@ -271,13 +291,9 @@ sub ArchiveCleanup # If the archive failed, clean up # if ( !$stat{xferOK} ) { - # - # wait a short while and see if the system is still alive - # $stat{hostError} = $stat{lastOutputLine} if ( $stat{hostError} eq "" ); - sleep(2); $stat{hostAbort} = 1; - $ArchiveLOG->write(\"Archive failed: $stat{hostError}\n") + $ArchiveLOG->write(\"Archive failed: $stat{hostError}") if ( defined($ArchiveLOG) ); } @@ -309,7 +325,7 @@ sub ArchiveCleanup return 1; } else { print(LOG $bpc->timeStamp, "Archive Complete\n"); - print("Archive Complete\n"); + print("archive complete\n"); return; } } @@ -335,9 +351,9 @@ sub pidHandler # sub UserCommandRun { - my($type) = @_; + my($cmdType) = @_; - return if ( !defined($Conf{$type}) ); + return if ( !defined($Conf{$cmdType}) ); my $vars = { xfer => $xfer, client => $client, @@ -357,10 +373,11 @@ sub UserCommandRun XferLOG => $ArchiveLOG, stat => \%stat, xferOK => $stat{xferOK} || 0, - type => $type, + type => "archive", + cmdType => $cmdType, }; - my $cmd = $bpc->cmdVarSubstitute($Conf{$type}, $vars); - $ArchiveLOG->write(\"Executing $type: @$cmd\n"); + my $cmd = $bpc->cmdVarSubstitute($Conf{$cmdType}, $vars); + $ArchiveLOG->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