X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_archive;h=f1fb9bd655d3756ba4b7096c25e538851f6f9340;hp=6ab75ea682e6acbb648eb84bb02a05e6a5c7280f;hb=b81d2da5e16975674f011e4833337ac0fa24e0ea;hpb=e951f787a66c5bd9e9955c3f657a5b44289c0fe1 diff --git a/bin/BackupPC_archive b/bin/BackupPC_archive index 6ab75ea..f1fb9bd 100644 --- a/bin/BackupPC_archive +++ b/bin/BackupPC_archive @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 2.1.0, released 20 Jun 2004. +# Version 3.0.0beta2, released 11 Nov 2006. # # See http://backuppc.sourceforge.net. # @@ -91,9 +91,30 @@ mkpath($Dir, 0, 0777) if ( !-d $Dir ); if ( !-f "$Dir/LOCK" ) { open(LOCK, ">", "$Dir/LOCK") && close(LOCK); } -open(LOG, ">>", "$Dir/LOG"); -select(LOG); $| = 1; select(STDOUT); +my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); +my $logPath = sprintf("$Dir/LOG.%02d%04d", $mon + 1, $year + 1900); + +if ( !-f $logPath ) { + # + # Compress and prune old log files + # + my $lastLog = $Conf{MaxOldPerPCLogFiles} - 1; + foreach my $file ( $bpc->sortedPCLogFiles($client) ) { + if ( $lastLog <= 0 ) { + unlink($file); + next; + } + $lastLog--; + next if ( $file =~ /\.z$/ || !$Conf{CompressLevel} ); + BackupPC::FileZIO->compressCopy($file, + "$file.z", + undef, + $Conf{CompressLevel}, 1); + } +} +open(LOG, ">>", $logPath); +select(LOG); $| = 1; select(STDOUT); # # Read the request file @@ -139,7 +160,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}); @@ -154,6 +178,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); @@ -268,7 +296,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");