From 510becee2f5c35e23c53d42d19fee2856c9b0682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Tue, 17 Jun 2025 13:32:59 +0200 Subject: [PATCH 1/5] get snpshots from list of datasets query the existing snapshots only from the configured datasets to avoud spinning up disks that are not in the config --- sanoid | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sanoid b/sanoid index 4a71319..aae3b5f 100755 --- a/sanoid +++ b/sanoid @@ -883,7 +883,8 @@ sub getsnaps { print "INFO: cache expired - updating from zfs list.\n"; } } - open FH, "$zfs get -Hrpt snapshot creation |"; + # just get snapshots from configured datasets to not spin up the disks + open FH, "$zfs get -Hrpt snapshot creation ".join(" ",keys %$config)." |"; @rawsnaps = ; close FH; From 24b0293b0fc4079498512dae80964600350dc3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Mon, 25 Aug 2025 17:52:48 +0200 Subject: [PATCH 2/5] fallback to old zfs list snapshot method in case of error --- sanoid | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sanoid b/sanoid index aae3b5f..895ede3 100755 --- a/sanoid +++ b/sanoid @@ -887,7 +887,13 @@ sub getsnaps { open FH, "$zfs get -Hrpt snapshot creation ".join(" ",keys %$config)." |"; @rawsnaps = ; close FH; - + $exit_code = $? >> 8; + if ($exit_code != 0) { + print "INFO: zfs list shapshots with dataset names does not work.. retrying without dataset names (this will spin-up all disks)\n"; + open FH, "$zfs get -Hrpt snapshot creation |"; + @rawsnaps = ; + close FH; + } open FH, "> $cache.tmp" or die "Could not write to $cache.tmp!\n"; print FH @rawsnaps; close FH; From 1c6d7d6459831d408a44ec27f5120500ebb592dd Mon Sep 17 00:00:00 2001 From: Bjoern Riemer Date: Sun, 9 Nov 2025 22:44:20 +0100 Subject: [PATCH 3/5] onl query not ignored datasets for snapshots --- sanoid | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/sanoid b/sanoid index 895ede3..c052e1c 100755 --- a/sanoid +++ b/sanoid @@ -144,6 +144,33 @@ if ($args{'cron'}) { exit 0; +#################################################################################### +#################################################################################### +#################################################################################### + +sub get_active_datasets { + my ($config, $snaps, $snapsbytype, $snapsbypath) = @_; + #my %datestamp = get_date(); + #my $errlevel = 0; + #my $msg; + #my @msgs; + my @paths; + + foreach my $section (keys %config) { + if ($section =~ /^template/) { next; } + if (! $config{$section}{'autoprune'}) { next; } + if (! $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 +} + #################################################################################### #################################################################################### #################################################################################### @@ -884,7 +911,7 @@ sub getsnaps { } } # just get snapshots from configured datasets to not spin up the disks - open FH, "$zfs get -Hrpt snapshot creation ".join(" ",keys %$config)." |"; + open FH, "$zfs get -Hrpt snapshot creation ".get_active_datasets(@params)." |"; @rawsnaps = ; close FH; $exit_code = $? >> 8; From 29f05ff5c42a5a984c9c84d2fd408ac0ccda4d7f Mon Sep 17 00:00:00 2001 From: Bjoern Date: Tue, 18 Nov 2025 12:14:06 +0100 Subject: [PATCH 4/5] fix dataset filter if autoprune is set --- sanoid | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/sanoid b/sanoid index c052e1c..d92e435 100755 --- a/sanoid +++ b/sanoid @@ -150,16 +150,11 @@ exit 0; sub get_active_datasets { my ($config, $snaps, $snapsbytype, $snapsbypath) = @_; - #my %datestamp = get_date(); - #my $errlevel = 0; - #my $msg; - #my @msgs; my @paths; foreach my $section (keys %config) { if ($section =~ /^template/) { next; } - if (! $config{$section}{'autoprune'}) { next; } - if (! $config{$section}{'autosnap'}) { next; } + if ((! $config{$section}{'autoprune'}) and (! $config{$section}{'autosnap'})) { next; } if ($config{$section}{'process_children_only'}) { next; } my $path = $config{$section}{'path'}; @@ -897,6 +892,7 @@ sub getsnaps { my ($config, $cacheTTL, $forcecacheupdate) = @_; my @rawsnaps; + my $exit_code; my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($cache); @@ -909,18 +905,19 @@ 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"; + } } # just get snapshots from configured datasets to not spin up the disks open FH, "$zfs get -Hrpt snapshot creation ".get_active_datasets(@params)." |"; - @rawsnaps = ; - close FH; - $exit_code = $? >> 8; + my $exit_code = $? >> 8; if ($exit_code != 0) { print "INFO: zfs list shapshots with dataset names does not work.. retrying without dataset names (this will spin-up all disks)\n"; open FH, "$zfs get -Hrpt snapshot creation |"; - @rawsnaps = ; - close FH; } + @rawsnaps = ; + close FH; open FH, "> $cache.tmp" or die "Could not write to $cache.tmp!\n"; print FH @rawsnaps; close FH; From 4415b36ba89f24f5b9b53d4f7cffbbb38a879195 Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Wed, 18 Feb 2026 20:36:42 +0100 Subject: [PATCH 5/5] fix error handling for fallback (old behaviour) and codestyle --- sanoid | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sanoid b/sanoid index d92e435..3f3f326 100755 --- a/sanoid +++ b/sanoid @@ -892,7 +892,7 @@ sub getsnaps { my ($config, $cacheTTL, $forcecacheupdate) = @_; my @rawsnaps; - my $exit_code; + my $exitcode; my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($cache); @@ -906,18 +906,23 @@ sub getsnaps { 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"; + print "INFO: running: $zfs get -Hrpt snapshot creation " . get_active_datasets(@params) . "\n"; } } - # just get snapshots from configured datasets to not spin up the disks - open FH, "$zfs get -Hrpt snapshot creation ".get_active_datasets(@params)." |"; - my $exit_code = $? >> 8; - if ($exit_code != 0) { - print "INFO: zfs list shapshots with dataset names does not work.. retrying without dataset names (this will spin-up all disks)\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 = ; 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 = ; + close FH; + } + open FH, "> $cache.tmp" or die "Could not write to $cache.tmp!\n"; print FH @rawsnaps; close FH;