BackupPC verification helper
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.7 KiB

#!/usr/bin/perl
use lib "/usr/share/BackupPC/lib";
use BackupPC::Lib;
use BackupPC::CGI::Lib;
5 years ago
use POSIX;
use JSON;
# We need to switch to backuppc UID/GID
my $uid = getuid();
my $gid = getgid();
my (undef,undef,$bkpuid,$bkpgid) = getpwnam('backuppc');
setuid($bkpuid) if ($uid ne $bkpuid);
setgid($bkpgid) if ($gid ne $bkpgid);
5 years ago
# Precise the host to check
my $host = $ARGV[0];
5 years ago
# Get values
my $bpc = BackupPC::Lib->new();
my @backups = $bpc->BackupInfoRead($host);
my $mainConf = $bpc->ConfigDataRead();
my $hostConf = $bpc->ConfigDataRead($host);
my $conf = { %$mainConf, %$hostConf };
my $fullCnt = $incrCnt = 0;
my $fullAge = $incrAge = $lastAge = -1;
my $lastXferErrors = 0;
my $maxErrors = 0;
for ( my $i = 0 ; $i < @backups ; $i++ ) {
if ( $backups[$i]{type} eq "full" ) {
$fullCnt++;
if ( $fullAge < 0 || $backups[$i]{startTime} > $fullAge ) {
$fullAge = $backups[$i]{startTime};
$fullSize0 = $backups[$i]{size};
$fullSize1 = $backups[$i]{size};
$fullSize2 = $backups[$i]{size};
$fullDur = $backups[$i]{endTime} - $backups[$i]{startTime};
}
}
else {
$incrCnt++;
if ( $incrAge < 0 || $backups[$i]{startTime} > $incrAge ) {
$incrAge = $backups[$i]{startTime};
}
}
}
if ( $fullAge > $incrAge && $fullAge >= 0 ) {
$lastAge = $fullAge;
}
else {
$lastAge = $incrAge;
}
if ( $lastAge < 0 ) {
$lastAge = "";
}
else {
$lastAge = sprintf("%.1f", (time - $lastAge) / (24 * 3600));
}
$lastXferErrors = $backups[@backups-1]{xferErrs} if ( @backups );
$maxErrors = $conf->{MaxXferError} if (defined $conf->{MaxXferError});
print<<"EOF";
5 years ago
Full Size of last backup : $fullSize0
Full Size of last -1 : $fullSize1
Full Size of last -2 : $fullSize2
EOF
exit(0);