Merge pull request #1009 from bjoern-r/snaplist-from-configured-datasets

get snpshots from configured list of datasets only
This commit is contained in:
Jim Salter 2026-02-18 17:07:02 -05:00 committed by GitHub
commit 31104a4488
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 37 additions and 1 deletions

38
sanoid
View File

@ -144,6 +144,28 @@ if ($args{'cron'}) {
exit 0;
####################################################################################
####################################################################################
####################################################################################
sub get_active_datasets {
my ($config, $snaps, $snapsbytype, $snapsbypath) = @_;
my @paths;
foreach my $section (keys %config) {
if ($section =~ /^template/) { next; }
if ((! $config{$section}{'autoprune'}) and (! $config{$section}{'autosnap'})) { next; }
if ($config{$section}{'process_children_only'}) { next; }
my $path = $config{$section}{'path'};
push @paths, $path;
}
my @sorted_paths = sort { lc($a) cmp lc($b) } @paths;
my $paths = join (" ", @sorted_paths);
return $paths
}
####################################################################################
####################################################################################
####################################################################################
@ -870,6 +892,7 @@ sub getsnaps {
my ($config, $cacheTTL, $forcecacheupdate) = @_;
my @rawsnaps;
my $exitcode;
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($cache);
@ -882,11 +905,24 @@ sub getsnaps {
} else {
print "INFO: cache expired - updating from zfs list.\n";
}
if ($args{'debug'}) {
print "INFO: running: $zfs get -Hrpt snapshot creation " . get_active_datasets(@params) . "\n";
}
}
open FH, "$zfs get -Hrpt snapshot creation |";
# just get snapshots from configured datasets
open FH, "$zfs get -Hrpt snapshot creation " . get_active_datasets(@params) . " |";
@rawsnaps = <FH>;
close FH;
my $exitcode = $? >> 8;
if ($exitcode != 0) {
print "INFO: zfs list shapshots with dataset names does not work, retrying without dataset names\n";
open FH, "$zfs get -Hrpt snapshot creation |";
@rawsnaps = <FH>;
close FH;
}
open FH, "> $cache.tmp" or die "Could not write to $cache.tmp!\n";
print FH @rawsnaps;
close FH;