Merge pull request #1 from darkbasic/feature/pre-post-scripts

Add pruning hooks
This commit is contained in:
Christoph Klaffl 2018-10-16 11:44:05 +02:00 committed by GitHub
commit a89d38b968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

11
sanoid
View File

@ -299,6 +299,17 @@ sub prune_snapshots {
if (! $args{'readonly'}) {
if (system($zfs, "destroy", $snap) == 0) {
$pruned{$snap} = 1;
my $dataset = (split '@', $snap)[0];
my $snapname = (split '@', $snap)[1];
if ($config{$dataset}{'pruning_script'}) {
$ENV{'SANOID_TARGET'} = $dataset;
$ENV{'SANOID_SNAPNAME'} = $snapname;
if ($args{'verbose'}) { print "executing pruning_script '".$config{$dataset}{'pruning_script'}."' on dataset '$dataset'\n"; }
system($config{$dataset}{'pruning_script'}) == 0
or warn "WARN: pruning_script failed, $?";
delete $ENV{'SANOID_TARGET'};
delete $ENV{'SANOID_SNAPNAME'};
}
} else {
warn "could not remove $snap : $?";
}

View File

@ -78,6 +78,8 @@
#no_inconsistent_snapshot = yes
### run post_snapshot_script when pre_snapshot_script is failing
#force_post_snapshot_script = yes
### dataset name will be supplied as an environment variable $SANOID_TARGET
pruning_script = /path/to/script.sh
[template_ignore]
autoprune = no

View File

@ -19,6 +19,7 @@ pre_snapshot_script =
post_snapshot_script =
no_inconsistent_snapshot =
force_post_snapshot_script =
pruning_script =
# 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.