Restructure to pass hashes around in take_snapshots

This commit makes it easier to pass structured data between the loop
which decides what to snapshot, and the loop performing the actual
snapshot.
This commit is contained in:
tiedotguy 2019-11-02 09:28:34 +11:00
parent 1f616e74cc
commit 6252cbf514
1 changed files with 16 additions and 33 deletions

49
sanoid
View File

@ -503,47 +503,30 @@ sub take_snapshots {
# update to most current possible datestamp # update to most current possible datestamp
%datestamp = get_date(); %datestamp = get_date();
# print "we should have had a $type snapshot of $path $maxage seconds ago; most recent is $newestage seconds old.\n"; # print "we should have had a $type snapshot of $path $maxage seconds ago; most recent is $newestage seconds old.\n";
my $snap = {
my $flags = ""; 'dataset' => $path,
# use zfs (atomic) recursion if specified in config 'snapshot' => "autosnap_$datestamp{'sortable'}_$type",
if ($config{$section}{'zfs_recursion'}) { 'recursive' => $config{$section}{'zfs_recrsion'}, # use zfs (atomic) recursion if specified in config
$flags .= "r"; 'handleDst' => $handleDst,
} };
if ($handleDst) { push(@newsnaps, $snap);
$flags .= "d";
}
if ($flags ne "") {
push(@newsnaps, "$path\@autosnap_$datestamp{'sortable'}_$type\@$flags");
} else {
push(@newsnaps, "$path\@autosnap_$datestamp{'sortable'}_$type");
}
} }
} }
} }
} }
if ( (scalar(@newsnaps)) > 0) { if ( (scalar(@newsnaps)) > 0) {
foreach my $snap ( @newsnaps ) { foreach my $snapData ( @newsnaps ) {
my $dataset = $snapData->{dataset};
my $snapname = $snapData->{snapshot};
my $recursiveFlag = $snapData->{recursive};
my $dstHandling = $snapData->{handleDst};
my $extraMessage = ""; my $extraMessage = "";
my @split = split '@', $snap, -1; if ($recursiveFlag) {
my $recursiveFlag = 0; $extraMessage = " (zfs recursive)";
my $dstHandling = 0;
if (scalar(@split) == 3) {
my $flags = $split[2];
if (index($flags, "r") != -1) {
$recursiveFlag = 1;
$extraMessage = " (zfs recursive)";
chop $snap;
}
if (index($flags, "d") != -1) {
$dstHandling = 1;
chop $snap;
}
chop $snap;
} }
my $dataset = $split[0]; my $snap = "$dataset\@$snapname";
my $snapname = $split[1];
my $presnapshotfailure = 0; my $presnapshotfailure = 0;
my $ret = 0; my $ret = 0;
if ($config{$dataset}{'pre_snapshot_script'}) { if ($config{$dataset}{'pre_snapshot_script'}) {