Skip to content

Commit

Permalink
sanoid jimsalterjrs#912: sanoid --prune-snapshots performance boost b…
Browse files Browse the repository at this point in the history
…y making --force-prune default (and adding --no-force-prune to get old behavior)
  • Loading branch information
sdettmer committed Apr 20, 2024
1 parent 45b1ce9 commit cab8e31
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions sanoid
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ my %args = (
GetOptions(\%args, "verbose", "debug", "cron", "readonly", "quiet",
"configdir=s", "cache-dir=s", "run-dir=s",
"monitor-health", "force-update",
"monitor-snapshots", "take-snapshots", "prune-snapshots", "force-prune",
"monitor-snapshots", "take-snapshots", "prune-snapshots",
"no-force-prune",
"monitor-capacity"
) or pod2usage(2);

Expand All @@ -40,7 +41,7 @@ my $cacheTTL = 900; # 15 minutes

# Allow a much older snapshot cache file than default if _only_ "--monitor-*" action commands are given
# (ignore "--verbose", "--configdir" etc)
if (($args{'monitor-snapshots'} || $args{'monitor-health'} || $args{'monitor-capacity'}) && ! ($args{'cron'} || $args{'force-update'} || $args{'take-snapshots'} || $args{'prune-snapshots'} || $args{'force-prune'})) {
if (($args{'monitor-snapshots'} || $args{'monitor-health'} || $args{'monitor-capacity'}) && ! ($args{'cron'} || $args{'force-update'} || $args{'take-snapshots'} || $args{'prune-snapshots'} || $args{'no-force-prune'})) {
# The command combination above must not assert true for any command that takes or prunes snapshots
$cacheTTL = 18000; # 5 hours
if ($args{'debug'}) { print "DEBUG: command combo means that the cache file (provided it exists) will be allowed to be older than default.\n"; }
Expand Down Expand Up @@ -349,7 +350,7 @@ sub prune_snapshots {
}

if ($args{'verbose'}) { print "INFO: pruning $snap ... \n"; }
if (!$args{'force-prune'} && iszfsbusy($path)) {
if ($args{'no-force-prune'} && iszfsbusy($path)) {
if ($args{'verbose'}) { print "INFO: deferring pruning of $snap - $path is currently in zfs send or receive.\n"; }
} else {
if (! $args{'readonly'}) {
Expand Down Expand Up @@ -1752,7 +1753,7 @@ Options:
--monitor-snapshots Reports on snapshot "health", in a Nagios compatible format
--take-snapshots Creates snapshots as specified in sanoid.conf
--prune-snapshots Purges expired snapshots as specified in sanoid.conf
--force-prune Purges expired snapshots even if a send/recv is in progress
--no-force-prune Double-check no send/recv is in progress before pruning

--help Prints this helptext
--version Prints the version number
Expand Down

0 comments on commit cab8e31

Please sign in to comment.