aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Beaupre <anarcat@koumbit.org>2009-06-16 10:51:29 -0400
committerAntoine Beaupre <anarcat@koumbit.org>2009-06-16 10:51:29 -0400
commite7ac16329b76d8a17fa7b247d55d3c3f7c9f2e10 (patch)
treec931c77fc0525b96ba7236a3ef9d33dfe4365ca9
parent245e6bde0c4c4a24f6b169aa88aaf0ff038241ac (diff)
downloadpuppet-backupninja-e7ac16329b76d8a17fa7b247d55d3c3f7c9f2e10.tar.gz
puppet-backupninja-e7ac16329b76d8a17fa7b247d55d3c3f7c9f2e10.tar.bz2
parse rdiff-backup logfile for the last real successful backup instead of just relying on the backup logfile timestamp
-rwxr-xr-xfiles/checkbackups.pl41
1 files changed, 32 insertions, 9 deletions
diff --git a/files/checkbackups.pl b/files/checkbackups.pl
index 5748f75..2084e86 100755
--- a/files/checkbackups.pl
+++ b/files/checkbackups.pl
@@ -41,10 +41,11 @@ my @vserver_dirs = qw{/var/lib/vservers /vservers};
our $opt_d = "/backup";
our $opt_c = 48 * 60 * 60;
our $opt_w = 24 * 60 * 60;
+our $opt_v = 0;
-if (!getopts('d:c:w:')) {
+if (!getopts('d:c:w:v')) {
print <<EOF
-Usage: $0 [ -d <backupdir> ] [ -c <threshold> ] [ -w <threshold> ]
+Usage: $0 [ -d <backupdir> ] [ -c <threshold> ] [ -w <threshold> ] -v
EOF
;
exit();
@@ -63,16 +64,33 @@ foreach $host (@hosts) {
chomp($host);
my $flag="";
my $type="unknown";
+ my $extra_msg="";
@vservers = ();
$state = $STATE_UNKNOWN;
$message = "???";
if (-d $host) {
# guess the backup type and find a proper stamp file to compare
- # XXX: this doesn't check if the backup was actually successful
# XXX: the backup type should be part of the machine registry
+ my $last_bak;
if (-d "$host/rdiff-backup") {
$flag="$host/rdiff-backup/rdiff-backup-data/backup.log";
$type="rdiff";
+ if (open(FLAG, $flag)) {
+ while (<FLAG>) {
+ if (/StartTime ([0-9]*).[0-9]* \((.*)\)/) {
+ $last_bak = $1;
+ $extra_msg = ' [backup.log]';
+ $opt_v && print STDERR "found timestamp $1 ($2) in backup.log\n";
+ }
+ }
+ if (!$last_bak) {
+ $message = "cannot parse backup.log for a valid timestamp";
+ next;
+ }
+ } else {
+ $opt_v && print STDERR "cannot open backup.log\n";
+ }
+ close(FLAG);
foreach my $vserver_dir (@vserver_dirs) {
$dir = "$host/rdiff-backup$vserver_dir";
if (opendir(DIR, $dir)) {
@@ -81,23 +99,28 @@ foreach $host (@hosts) {
}
}
} elsif (-d "$host/dump") {
+ # XXX: this doesn't check backup consistency
$flag="$host/dump/" . `ls -tr $host/dump | tail -1`;
chomp($flag);
$type="dump";
} elsif (-d "$host/dup") {
+ # XXX: this doesn't check backup consistency
$flag="$host/dup";
$type="duplicity";
} else {
$message = "unknown system";
next;
}
- my @stats = stat($flag);
- if (not @stats) {
- $message = "cannot stat flag $flag";
- next;
+ if (!defined($last_bak)) {
+ my @stats = stat($flag);
+ if (not @stats) {
+ $message = "cannot stat flag $flag";
+ next;
+ }
+ $last_bak = $stats[9];
}
my $t = time();
- my $delta = $t - $stats[9];
+ my $delta = $t - $last_bak;
if ($delta > $crit) {
$state = $STATE_CRITICAL;
} elsif ($delta > $warn) {
@@ -105,7 +128,7 @@ foreach $host (@hosts) {
} elsif ($delta >= 0) {
$state = $STATE_OK;
}
- $message = "$delta seconds old";
+ $message = "$delta seconds old$extra_msg";
} else {
$message = "no directory";
}