Add pre and post snapshot scripts
This commit is contained in:
parent
eeedf38d57
commit
0cce7074c7
25
sanoid
25
sanoid
|
@ -455,6 +455,18 @@ sub take_snapshots {
|
||||||
|
|
||||||
if ( (scalar(@newsnaps)) > 0) {
|
if ( (scalar(@newsnaps)) > 0) {
|
||||||
foreach my $snap ( @newsnaps ) {
|
foreach my $snap ( @newsnaps ) {
|
||||||
|
my $dataset = (split '@', $snap)[0];
|
||||||
|
my $presnapshotfailure = 0;
|
||||||
|
if ($config{$dataset}{'pre_snapshot_script'} and !$args{'readonly'}) {
|
||||||
|
$ENV{'SANOID_TARGET'} = $dataset;
|
||||||
|
if ($args{'verbose'}) { print "executing pre_snapshot_script '".$config{$dataset}{'pre_snapshot_script'}."' on dataset '$dataset'\n"; }
|
||||||
|
if (system($config{$dataset}{'pre_snapshot_script'}) != 0) {
|
||||||
|
warn "WARN: pre_snapshot_script failed, $?";
|
||||||
|
$config{$dataset}{'no_inconsistent_snapshot'} and next;
|
||||||
|
$presnapshotfailure = 1;
|
||||||
|
}
|
||||||
|
delete $ENV{'SANOID_TARGET'};
|
||||||
|
}
|
||||||
if ($args{'verbose'}) { print "taking snapshot $snap\n"; }
|
if ($args{'verbose'}) { print "taking snapshot $snap\n"; }
|
||||||
if (!$args{'readonly'}) {
|
if (!$args{'readonly'}) {
|
||||||
system($zfs, "snapshot", "$snap") == 0
|
system($zfs, "snapshot", "$snap") == 0
|
||||||
|
@ -462,6 +474,17 @@ sub take_snapshots {
|
||||||
# make sure we don't end up with multiple snapshots with the same ctime
|
# make sure we don't end up with multiple snapshots with the same ctime
|
||||||
sleep 1;
|
sleep 1;
|
||||||
}
|
}
|
||||||
|
if ($config{$dataset}{'post_snapshot_script'} and !$args{'readonly'}) {
|
||||||
|
if (!$presnapshotfailure or $config{$dataset}{'force_post_snapshot_script'}) {
|
||||||
|
$ENV{'SANOID_TARGET'} = $dataset;
|
||||||
|
if ($args{'verbose'}) { print "executing post_snapshot_script '".$config{$dataset}{'post_snapshot_script'}."' on dataset '$dataset'\n"; }
|
||||||
|
if (system($config{$dataset}{'post_snapshot_script'}) != 0) {
|
||||||
|
warn "WARN: post_snapshot_script failed, $?";
|
||||||
|
$config{$dataset}{'no_inconsistent_snapshot'} and next;
|
||||||
|
}
|
||||||
|
delete $ENV{'SANOID_TARGET'};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$forcecacheupdate = 1;
|
$forcecacheupdate = 1;
|
||||||
%snaps = getsnaps(%config,$cacheTTL,$forcecacheupdate);
|
%snaps = getsnaps(%config,$cacheTTL,$forcecacheupdate);
|
||||||
|
@ -661,7 +684,7 @@ sub init {
|
||||||
tie my %ini, 'Config::IniFiles', ( -file => $conf_file ) or die "FATAL: cannot load $conf_file - please create a valid local config file before running sanoid!";
|
tie my %ini, 'Config::IniFiles', ( -file => $conf_file ) or die "FATAL: cannot load $conf_file - please create a valid local config file before running sanoid!";
|
||||||
|
|
||||||
# we'll use these later to normalize potentially true and false values on any toggle keys
|
# we'll use these later to normalize potentially true and false values on any toggle keys
|
||||||
my @toggles = ('autosnap','autoprune','monitor_dont_warn','monitor_dont_crit','monitor','recursive','process_children_only');
|
my @toggles = ('autosnap','autoprune','monitor_dont_warn','monitor_dont_crit','monitor','recursive','process_children_only','no_inconsistent_snapshot','force_post_snapshot_script');
|
||||||
my @istrue=(1,"true","True","TRUE","yes","Yes","YES","on","On","ON");
|
my @istrue=(1,"true","True","TRUE","yes","Yes","YES","on","On","ON");
|
||||||
my @isfalse=(0,"false","False","FALSE","no","No","NO","off","Off","OFF");
|
my @isfalse=(0,"false","False","FALSE","no","No","NO","off","Off","OFF");
|
||||||
|
|
||||||
|
|
11
sanoid.conf
11
sanoid.conf
|
@ -67,6 +67,17 @@
|
||||||
daily_warn = 48
|
daily_warn = 48
|
||||||
daily_crit = 60
|
daily_crit = 60
|
||||||
|
|
||||||
|
[template_scripts]
|
||||||
|
### run script before snapshot
|
||||||
|
### dataset name will be supplied as an environment variable $SANOID_TARGET
|
||||||
|
pre_snapshot_script = /path/to/script.sh
|
||||||
|
### run script after snapshot
|
||||||
|
### dataset name will be supplied as an environment variable $SANOID_TARGET
|
||||||
|
post_snapshot_script = /path/to/script.sh
|
||||||
|
### don't take an inconsistent snapshot
|
||||||
|
#no_inconsistent_snapshot = yes
|
||||||
|
### run post_snapshot_script when pre_snapshot_script is failing
|
||||||
|
#force_post_snapshot_script = yes
|
||||||
|
|
||||||
[template_ignore]
|
[template_ignore]
|
||||||
autoprune = no
|
autoprune = no
|
||||||
|
|
|
@ -15,6 +15,10 @@ path =
|
||||||
recursive =
|
recursive =
|
||||||
use_template =
|
use_template =
|
||||||
process_children_only =
|
process_children_only =
|
||||||
|
pre_snapshot_script =
|
||||||
|
post_snapshot_script =
|
||||||
|
no_inconsistent_snapshot =
|
||||||
|
force_post_snapshot_script =
|
||||||
|
|
||||||
# If any snapshot type is set to 0, we will not take snapshots for it - and will immediately
|
# If any snapshot type is set to 0, we will not take snapshots for it - and will immediately
|
||||||
# prune any of those type snapshots already present.
|
# prune any of those type snapshots already present.
|
||||||
|
|
Loading…
Reference in New Issue