X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_restore;h=8af7550d4f1c1f0f792ac9d26aea53ea93a96cdf;hp=3f58ca6879e144395b1c40f5dd0231627f6c5594;hb=refs%2Ftags%2Fv3_0_0beta1;hpb=e6fc5dc667cbf97c374da04c55d24e4ea83ec865 diff --git a/bin/BackupPC_restore b/bin/BackupPC_restore index 3f58ca6..8af7550 100755 --- a/bin/BackupPC_restore +++ b/bin/BackupPC_restore @@ -29,7 +29,7 @@ # #======================================================================== # -# Version 3.0.0beta0, released 11 Jul 2006. +# Version 3.0.0beta1, released 30 Jul 2006. # # See http://backuppc.sourceforge.net. # @@ -101,9 +101,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 @@ -196,6 +217,7 @@ my $RestoreLOG = BackupPC::FileZIO->open("$Dir/RestoreLOG$fileExt", 1, $Conf{CompressLevel}); my $tarCreateFileCnt = 0; my $tarCreateByteCnt = 0; +my $tarCreateDirCnt = 0; my $tarCreateErrCnt = 1; # assume not ok until we learn otherwise my $tarCreateErr; my($logMsg, $xfer); @@ -329,10 +351,10 @@ if ( $useTar ) { @tarPathOpts, @{$RestoreReq{fileList}}, ); - my $logMsg = "Running: " + my $runMsg = "Running: " . $bpc->execCmd2ShellCmd("$BinDir/BackupPC_tarCreate", @tarArgs) . "\n"; - $RestoreLOG->write(\$logMsg); + $RestoreLOG->write(\$runMsg); if ( !defined($tarPid = open(TAR, "-|")) ) { close(WH); # FIX: need to cleanup xfer @@ -402,6 +424,7 @@ if ( $useTar ) { if ( /^Done: (\d+) files, (\d+) bytes, (\d+) dirs, (\d+) specials, (\d+) errors/ ) { $tarCreateFileCnt = $1; $tarCreateByteCnt = $2; + $tarCreateDirCnt = $3; $tarCreateErrCnt = $5; } } @@ -426,7 +449,7 @@ if ( $useTar ) { # # otherwise the xfer module does everything for us # - print(LOG $bpc->timeStamp, "Starting restore\n"); + print(LOG $bpc->timeStamp, $logMsg . "\n"); print("started_restore\n"); ($tarCreateFileCnt, $tarCreateByteCnt, $tarCreateErrCnt, $tarCreateErr) = $xfer->run(); @@ -573,7 +596,7 @@ sub RestoreCleanup if ( $stat{hostAbort} && $stat{hostError} eq "" ) { $stat{hostError} = "lost network connection during restore"; } - $RestoreLOG->write(\"Restore failed: $stat{hostError}\n") + $RestoreLOG->write(\"restore failed: $stat{hostError}\n") if ( defined($RestoreLOG) ); } @@ -604,10 +627,14 @@ sub RestoreCleanup $bpc->RestoreInfoWrite($client, @Restores); if ( !$stat{xferOK} ) { - print(LOG $bpc->timeStamp, "Restore failed ($stat{hostError})\n"); + print(LOG $bpc->timeStamp, "restore failed ($stat{hostError})\n"); print("restore failed: $stat{hostError}\n"); return 1; } else { + $stat{xferErrCnt} ||= 0; + print(LOG $bpc->timeStamp, "restore $lastNum complete" + . " ($tarCreateFileCnt files, $tarCreateByteCnt bytes," + . " $tarCreateDirCnt dirs, $stat{xferErrCnt} xferErrs)\n"); print("restore complete\n"); return; }