# DESCRIPTION
#
# BackupPC reads the configuration and status information from
-# $TopDir/conf. It then runs and manages all the backup activity.
+# $ConfDir/conf. It then runs and manages all the backup activity.
#
# As specified by $Conf{WakeupSchedule}, BackupPC wakes up periodically
# to queue backups on all the PCs. This is a four step process:
# Craig Barratt <cbarratt@users.sourceforge.net>
#
# COPYRIGHT
-# Copyright (C) 2001-2003 Craig Barratt
+# Copyright (C) 2001-2007 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, released 20 Jun 2004.
+# Version 3.1.0, released 25 Nov 2007.
#
# See http://backuppc.sourceforge.net.
#
use lib "/usr/local/BackupPC/lib";
use BackupPC::Lib;
use BackupPC::FileZIO;
+use Encode qw/decode_utf8/;
use File::Path;
use Data::Dumper;
die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
my $TopDir = $bpc->TopDir();
my $BinDir = $bpc->BinDir();
+my $LogDir = $bpc->LogDir();
my %Conf = $bpc->Conf();
#
#
# Read old status
#
-if ( -f "$TopDir/log/status.pl" && !(my $ret = do "$TopDir/log/status.pl") ) {
- die "couldn't parse $TopDir/log/status.pl: $@" if $@;
- die "couldn't do $TopDir/log/status.pl: $!" unless defined $ret;
- die "couldn't run $TopDir/log/status.pl";
+if ( -f "$LogDir/status.pl" && !(my $ret = do "$LogDir/status.pl") ) {
+ if ( $@ ) {
+ print STDERR "couldn't parse $LogDir/status.pl: $@";
+ } elsif ( !defined($ret) ) {
+ print STDERR "couldn't do $LogDir/status.pl: $!";
+ } else {
+ print STDERR "couldn't run $LogDir/status.pl";
+ }
}
#
umask($Conf{UmaskMode});
#
- # Check for another running process, check that PASSWD is set and
- # verify executables are configured correctly.
+ # Check for another running process, verify executables are configured
+ # correctly and make sure $TopDir is on a file system that supports
+ # hardlinks.
#
if ( $Info{pid} ne "" && kill(0, $Info{pid}) ) {
print(STDERR $bpc->timeStamp,
"Another BackupPC is running (pid $Info{pid}); quitting...\n");
exit(1);
}
+
foreach my $progName ( qw(SmbClientPath NmbLookupPath PingPath DfPath
SendmailPath SshPath) ) {
next if ( $Conf{$progName} eq "" || -x $Conf{$progName} );
exit(1);
}
+ if ( !$bpc->HardlinkTest("$TopDir/pc", "$TopDir/cpool") ) {
+ print(STDERR $bpc->timeStamp, "Can't create a test hardlink between a file"
+ . " in $TopDir/pc and $TopDir/cpool. Either these are different"
+ . " file systems, or this file system doesn't support hardlinks,"
+ . " or these directories don't exist, or there is a permissions"
+ . " problem, or the file system is out of inodes or full. Use"
+ . " df, df -i, and ls -ld to check each of these possibilities."
+ . " Quitting...\n");
+ exit(1);
+ }
+
if ( $opts{d} ) {
#
# daemonize by forking; more robust method per:
# Write out our initial status and save our PID
#
StatusWrite();
- if ( open(PID, ">", "$TopDir/log/BackupPC.pid") ) {
+ unlink("$LogDir/BackupPC.pid");
+ if ( open(PID, ">", "$LogDir/BackupPC.pid") ) {
print(PID $$);
close(PID);
+ chmod(0444, "$LogDir/BackupPC.pid");
}
#
});
$CmdQueueOn{$bpc->trashJob} = 1;
}
- if ( keys(%Jobs) == $trashCleanRunning && $RunNightlyWhenIdle == 1 ) {
+ if ( $RunNightlyWhenIdle == 1 ) {
#
# Queue multiple nightly jobs based on the configuration
}
if ( !$pid ) {
setpgrp 0,0;
+ $ENV{BPC_REQUSER} = $req->{user};
exec(@$cmd);
print(LOG $bpc->timeStamp, "can't exec @$cmd for $host\n");
exit(0);
}
}
- while ( $RunNightlyWhenIdle == 0 ) {
+ #
+ # Run background jobs anytime. Previously they were locked out
+ # when BackupPC_nightly was running or pending with this
+ # condition on the while loop:
+ #
+ # while ( $RunNightlyWhenIdle == 0 )
+ #
+ while ( 1 ) {
local(*FH);
my(@args, $progName, $type);
my $nJobs = keys(%Jobs);
$Info{DUDailySkipHostCntPrev} = $Info{DUDailySkipHostCnt};
$Info{DUDailySkipHostCnt} = 0;
my $lastLog = $Conf{MaxOldLogFiles} - 1;
- if ( -f "$TopDir/log/LOG.$lastLog" ) {
+ if ( -f "$LogDir/LOG.$lastLog" ) {
print(LOG $bpc->timeStamp,
- "Removing $TopDir/log/LOG.$lastLog\n");
- unlink("$TopDir/log/LOG.$lastLog");
+ "Removing $LogDir/LOG.$lastLog\n");
+ unlink("$LogDir/LOG.$lastLog");
}
- if ( -f "$TopDir/log/LOG.$lastLog.z" ) {
+ if ( -f "$LogDir/LOG.$lastLog.z" ) {
print(LOG $bpc->timeStamp,
- "Removing $TopDir/log/LOG.$lastLog.z\n");
- unlink("$TopDir/log/LOG.$lastLog.z");
+ "Removing $LogDir/LOG.$lastLog.z\n");
+ unlink("$LogDir/LOG.$lastLog.z");
}
print(LOG $bpc->timeStamp, "Aging LOG files, LOG -> LOG.0 -> "
. "LOG.1 -> ... -> LOG.$lastLog\n");
close(LOG);
for ( my $i = $lastLog - 1 ; $i >= 0 ; $i-- ) {
my $j = $i + 1;
- rename("$TopDir/log/LOG.$i", "$TopDir/log/LOG.$j")
- if ( -f "$TopDir/log/LOG.$i" );
- rename("$TopDir/log/LOG.$i.z", "$TopDir/log/LOG.$j.z")
- if ( -f "$TopDir/log/LOG.$i.z" );
+ rename("$LogDir/LOG.$i", "$LogDir/LOG.$j")
+ if ( -f "$LogDir/LOG.$i" );
+ rename("$LogDir/LOG.$i.z", "$LogDir/LOG.$j.z")
+ if ( -f "$LogDir/LOG.$i.z" );
}
#
# Compress the log file LOG -> LOG.0.z (if enabled).
# Otherwise, just rename LOG -> LOG.0.
#
- BackupPC::FileZIO->compressCopy("$TopDir/log/LOG",
- "$TopDir/log/LOG.0.z",
- "$TopDir/log/LOG.0",
+ BackupPC::FileZIO->compressCopy("$LogDir/LOG",
+ "$LogDir/LOG.0.z",
+ "$LogDir/LOG.0",
$Conf{CompressLevel}, 1);
LogFileOpen();
#
- # Remember to run nightly script after current jobs are done
+ # Remember to run the nightly script when the next CmdQueue
+ # job is done.
#
$RunNightlyWhenIdle = 1;
}
#
# This means the last BackupPC_nightly is done with
# the pool clean, so it's ok to start running regular
- # backups again.
+ # backups again. But starting in 3.0 regular jobs
+ # are decoupled from BackupPC_nightly.
#
$RunNightlyWhenIdle = 0;
}
#print(LOG $bpc->timeStamp, "BackupPC_nightly done; now"
# . " have $BackupPCNightlyJobs running\n");
if ( $BackupPCNightlyJobs <= 0 ) {
+ #
+ # Last BackupPC_nightly has finished
+ #
$BackupPCNightlyJobs = 0;
$RunNightlyWhenIdle = 0;
$CmdJob = "";
last;
}
$Clients{$client}{mesgCnt}++;
- $cmd = $2;
+ $cmd = decode_utf8($2);
if ( $cmd =~ /^stop (\S+)\s+(\S+)\s+(\S*)/ ) {
$host = $1;
my $user = $2;
###########################################################################
#
-# Write the current status to $TopDir/log/status.pl
+# Write the current status to $LogDir/status.pl
#
sub StatusWrite
{
[ \%Info, \%Status],
[qw(*Info *Status)]);
$dump->Indent(1);
- if ( open(STATUS, ">", "$TopDir/log/status.pl") ) {
- print(STATUS $dump->Dump);
- close(STATUS);
- }
+ my $text = $dump->Dump;
+ $bpc->{storage}->TextFileWrite("$LogDir/status.pl", $text);
}
#
close(LOG);
LogFileOpen();
print(LOG "Fatal error: unhandled signal $SigName\n");
- unlink("$TopDir/log/BackupPC.pid");
+ unlink("$LogDir/BackupPC.pid");
confess("Got new signal $SigName... quitting\n");
} else {
$SigName = shift;
#
sub LogFileOpen
{
- mkpath("$TopDir/log", 0, 0777) if ( !-d "$TopDir/log" );
- open(LOG, ">>$TopDir/log/LOG")
- || die("Can't create LOG file $TopDir/log/LOG");
+ mkpath($LogDir, 0, 0777) if ( !-d $LogDir );
+ open(LOG, ">>$LogDir/LOG")
+ || die("Can't create LOG file $LogDir/LOG");
close(STDOUT);
close(STDERR);
open(STDOUT, ">&LOG");
print(LOG $bpc->timeStamp, "unix socket() failed: $!\n");
exit(1);
}
- my $sockFile = "$TopDir/log/BackupPC.sock";
+ my $sockFile = "$LogDir/BackupPC.sock";
unlink($sockFile);
if ( !bind(SERVER_UNIX, sockaddr_un($sockFile)) ) {
print(LOG $bpc->timeStamp, "unix bind() failed: $!\n");
}
delete($Info{pid});
StatusWrite();
- unlink("$TopDir/log/BackupPC.pid");
+ unlink("$LogDir/BackupPC.pid");
exit(1);
}