Commit b1ad64a1 authored by Antoine Beaupré's avatar Antoine Beaupré

look into subdirectories for multiple backups per hosts

we still have a somewhat fucked up structure here, but that's how we use it at koumbit right now
parent 7de608b0
...@@ -53,8 +53,8 @@ EOF ...@@ -53,8 +53,8 @@ EOF
} }
sub check_rdiff { sub check_rdiff {
my ($host, $dir, $subdir, $optv) = @_; my ($host, $dir, $optv) = @_;
my $flag="$dir/$subdir/rdiff-backup-data/backup.log"; my $flag="$dir/rdiff-backup-data/backup.log";
my $extra_msg = ''; my $extra_msg = '';
my @vservers; my @vservers;
if (open(FLAG, $flag)) { if (open(FLAG, $flag)) {
...@@ -74,9 +74,17 @@ sub check_rdiff { ...@@ -74,9 +74,17 @@ sub check_rdiff {
} }
close(FLAG); close(FLAG);
($state, $delta) = check_age($last_bak); ($state, $delta) = check_age($last_bak);
print_status($host, $state, "$delta seconds old$extra_msg"); $dir =~ /([^\/]*)\/rdiff-backup/;
if ($1 ne $host) {
# special subdir backup
$service = "backups-$1";
}
else {
$service = 'backups';
}
print_status($host, $state, "$delta seconds old$extra_msg", $service);
foreach my $vserver_dir (@vserver_dirs) { foreach my $vserver_dir (@vserver_dirs) {
$vsdir = "$dir/${subdir}$vserver_dir"; $vsdir = "$dir/$vserver_dir";
if (opendir(DIR, $vsdir)) { if (opendir(DIR, $vsdir)) {
@vservers = grep { /^[^\.]/ && -d "$vsdir/$_" } readdir(DIR); @vservers = grep { /^[^\.]/ && -d "$vsdir/$_" } readdir(DIR);
$opt_v && print STDERR "found vservers $vsdir: @vservers\n"; $opt_v && print STDERR "found vservers $vsdir: @vservers\n";
...@@ -107,8 +115,11 @@ sub check_age { ...@@ -107,8 +115,11 @@ sub check_age {
} }
sub print_status { sub print_status {
my ($host, $state, $message) = @_; my ($host, $state, $message, $service) = @_;
printf "$host\tbackups\t$state\t$message\n"; if (!$service) {
$service = 'backups';
}
printf "$host\t$service\t$state\t$message\n";
} }
sub check_flag { sub check_flag {
...@@ -142,13 +153,19 @@ foreach $host (@hosts) { ...@@ -142,13 +153,19 @@ foreach $host (@hosts) {
} else { } else {
$dir = $host; $dir = $host;
} }
my $flag=""; my $flag;
if (-d $dir) { if (-d $dir) {
# guess the backup type and find a proper stamp file to compare # guess the backup type and find a proper stamp file to compare
# XXX: the backup type should be part of the machine registry @rdiffs = glob("$dir/*/*/rdiff-backup-data");
my $last_bak; foreach $dir (@rdiffs) {
$opt_v && print STDERR "inspecting dir $dir\n";
$dir =~ s/rdiff-backup-data$//;
check_rdiff($host, $dir, $opt_v);
$flag = 1;
}
if (-d "$dir/rdiff-backup") { if (-d "$dir/rdiff-backup") {
check_rdiff($host, $dir, 'rdiff-backup', $opt_v); check_rdiff($host, $dir . '/rdiff-backup', $opt_v);
$flag = 1;
} elsif (-d "$dir/dump") { } elsif (-d "$dir/dump") {
# XXX: this doesn't check backup consistency # XXX: this doesn't check backup consistency
$flag="$dir/dump/" . `ls -tr $dir/dump | tail -1`; $flag="$dir/dump/" . `ls -tr $dir/dump | tail -1`;
...@@ -163,7 +180,8 @@ foreach $host (@hosts) { ...@@ -163,7 +180,8 @@ foreach $host (@hosts) {
# XXX: this doesn't check backup consistency # XXX: this doesn't check backup consistency
$flag="$dir/rsync.log"; $flag="$dir/rsync.log";
check_flag($host, $flag); check_flag($host, $flag);
} else { }
if (!$flag) {
print_status($host, $STATE_UNKNOWN, 'unknown system'); print_status($host, $STATE_UNKNOWN, 'unknown system');
} }
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment