forked from jollyjinx/ZFS-TimeMachine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkbackup.perl
executable file
·57 lines (43 loc) · 1.59 KB
/
checkbackup.perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl
#
# purpose: simple script to see if the backup script runs smooethly.
#
# example usage: perl checkbackup.perl --pool=puddle --snapshotinterval=300
#
# this will check if the pool puddle has a snapshot made within the last 10 minutes since wake/boot
#
use JNX::Configuration;
my %commandlineoption = JNX::Configuration::newFromDefaults( {
'pools' => ['puddle','string'],
'snapshotinterval' => [300,'number'],
'snapshottime' => [10,'number'],
}, __PACKAGE__ );
use strict;
use JNX::ZFS;
use JNX::System;
JNX::System::checkforrunningmyself($commandlineoption{'pools'}) || die "Already running which means lookup for snapshots is too slow";
my $lastwaketime = JNX::System::lastwaketime();
my @poolstotest = split(/,/,$commandlineoption{'pools'});
for my $pooltotest (@poolstotest)
{
print STDERR "Testing pool: $pooltotest\n";
my @snapshots = JNX::ZFS::getsnapshotsforpool($pooltotest);
# print STDERR "Snapshots: @snapshots\n";
my $snapshottime = JNX::ZFS::timeofsnapshot( pop @snapshots );
my $snapshotoffset = (2 * $commandlineoption{'snapshotinterval'}) + $commandlineoption{'snapshottime'};
if( $snapshottime + $snapshotoffset < time() )
{
if( $lastwaketime + $snapshotoffset < time() )
{
print STDERR "Last snapshot for pool (".$pooltotest."):".localtime($snapshottime)." - too old\n";
exit 1;
}
else
{
print STDERR "Not long enough after reboot\n";
exit 0;
}
}
print STDERR "Last snapshot for pool (".$pooltotest."):".localtime($snapshottime)." - ok\n";
}
exit 0;