-
Notifications
You must be signed in to change notification settings - Fork 14
/
autoscrub.perl
executable file
·66 lines (47 loc) · 1.53 KB
/
autoscrub.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
57
58
59
60
61
62
63
64
#!/usr/bin/perl
#
# purpose: simple script to automatically scub zpools when needed
#
# example usage: perl autoscrub.perl --scrubinterval=7
#
# this will start a scrub on all pools if the last scrub was 7 days or longer ago
#
use JNX::Configuration;
my %commandlineoption = JNX::Configuration::newFromDefaults( {
'host' => ['','string'],
'hostoptions' => ['-c blowfish -C -l root','string'],
'pools' => ['allavailablepools','string'],
'scrubinterval' => [7,'number'],
'verbose' => [0,'flag'],
'debug' => [0,'flag'],
}, __PACKAGE__ );
$commandlineoption{verbose}=1 if $commandlineoption{debug};
my %host = ( host => $commandlineoption{host}, hostoptions => $commandlineoption{hostoptions} , debug=>$commandlineoption{debug},verbose=>$commandlineoption{verbose});
use strict;
use JNX::ZFS;
use JNX::System;
my %pools = %{ JNX::ZFS::pools( %host ) };
my @scrubpools;
if( $commandlineoption{pools} eq 'allavailablepools' )
{
@scrubpools = (keys %pools);
}
else
{
@scrubpools = split( /[,\s]/,$commandlineoption{pools} );
}
for my $pool (@scrubpools )
{
if( defined $pools{$pool} )
{
if( $pools{$pool}{lastscrub} < ( time() - (86400*$commandlineoption{scrubinterval})) )
{
die "could not start scrub: $!" if !defined(JNX::System::executecommand(%host, command=> 'zpool scrub '.$pool));
print "$pool: starting scrub \n";
}
else
{
print "$pool: no scrub needed\n";
}
}
}