-#!/bin/perl -T
+#!/bin/perl
#============================================================= -*-perl-*-
#
# BackupPC_archive: Archive files for an archive client.
# Usage: BackupPC_archive <user> <archiveclient> <reqFileName>
#
# AUTHOR
-# Craig Barratt <cbarratt@users.sourceforge.net>
+# 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
#
#========================================================================
#
-# Version 2.1.0_CVS, released 3 Jul 2003.
+# Version 2.1.0, released 20 Jun 2004.
#
# See http://backuppc.sourceforge.net.
#
my $startTime = time();
-#my $Hosts = $bpc->HostInfoRead($client);
-
my $Dir = "$TopDir/pc/$client";
my @xferPid = ();
$stat{hostError} = $err;
exit(ArchiveCleanup($client));
}
+
#
# Re-read config file, so we can include the PC-specific config
#
}
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));
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);
+ }
}
}
# 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) );
}
return 1;
} else {
print(LOG $bpc->timeStamp, "Archive Complete\n");
- print("Archive Complete\n");
+ print("archive complete\n");
return;
}
}
#
sub UserCommandRun
{
- my($type) = @_;
+ my($cmdType) = @_;
- return if ( !defined($Conf{$type}) );
+ return if ( !defined($Conf{$cmdType}) );
my $vars = {
xfer => $xfer,
client => $client,
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