From da3186f33aec1800433c8cf6e44989ac844fdeb6 Mon Sep 17 00:00:00 2001 From: Heuzef Date: Thu, 19 Sep 2019 14:19:55 +0200 Subject: [PATCH] Add check size consistency script --- check_size_consistency.pl | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 check_size_consistency.pl diff --git a/check_size_consistency.pl b/check_size_consistency.pl new file mode 100644 index 0000000..e17f8b4 --- /dev/null +++ b/check_size_consistency.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl +use lib "/usr/share/BackupPC/lib"; +use BackupPC::Lib; +use BackupPC::CGI::Lib; +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); + +my $host = $ARGV[0]; + +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}; + $fullSize = $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"; + +Full Size of last backup : $fullSize +EOF + +exit(0);