From d097da58fb0a5d831bd5c5ac745c3ad7f3741cdd Mon Sep 17 00:00:00 2001 From: Lenz Weber Date: Mon, 14 Feb 2022 19:25:44 +0100 Subject: [PATCH 1/3] add "cleanup_only" configuration to skip snapshotting --- bin/zfs-auto-snapshot | 2 ++ lib/zfstools.rb | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/zfs-auto-snapshot b/bin/zfs-auto-snapshot index ee717c5..ac42861 100755 --- a/bin/zfs-auto-snapshot +++ b/bin/zfs-auto-snapshot @@ -71,5 +71,7 @@ datasets = find_eligible_datasets(interval, pool) # Generate new snapshots do_new_snapshots(datasets, interval) if keep > 0 +datasets = find_eligible_datasets(interval, pool, ['cleanup_only']) + # Delete expired cleanup_expired_snapshots(pool, datasets, interval, keep, should_destroy_zero_sized_snapshots) diff --git a/lib/zfstools.rb b/lib/zfstools.rb index f31957e..810fb2d 100644 --- a/lib/zfstools.rb +++ b/lib/zfstools.rb @@ -105,8 +105,9 @@ def find_recursive_datasets(datasets) ### Find eligible datasets -def filter_datasets(datasets, included_excluded_datasets, property) +def filter_datasets(datasets, included_excluded_datasets, property, extra_eligible) all_datasets = included_excluded_datasets['included'] + included_excluded_datasets['excluded'] + eligible_values = ["true","mysql","postgresql"] + extra_eligible datasets.each do |dataset| # If the dataset is already included/excluded, skip it (for override checking) @@ -115,7 +116,7 @@ def filter_datasets(datasets, included_excluded_datasets, property) # Exclude unmounted datasets. if (dataset.properties['mounted'] == "yes" or dataset.properties['type'] == "volume") and - ["true","mysql","postgresql"].include? value + eligible_values.include? value included_excluded_datasets['included'] << dataset elsif value included_excluded_datasets['excluded'] << dataset @@ -123,7 +124,7 @@ def filter_datasets(datasets, included_excluded_datasets, property) end end -def find_eligible_datasets(interval, pool) +def find_eligible_datasets(interval, pool, extra_eligible = []) properties = [ "#{snapshot_property}:#{interval}", snapshot_property, From 4e4415650953838956e495d9611bd5c6b24463c2 Mon Sep 17 00:00:00 2001 From: Lenz Weber Date: Mon, 14 Feb 2022 20:09:50 +0100 Subject: [PATCH 2/3] fixup --- lib/zfstools.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zfstools.rb b/lib/zfstools.rb index 810fb2d..72dcba7 100644 --- a/lib/zfstools.rb +++ b/lib/zfstools.rb @@ -139,9 +139,9 @@ def find_eligible_datasets(interval, pool, extra_eligible = []) } # Gather the datasets given the override property - filter_datasets datasets, included_excluded_datasets, "#{snapshot_property}:#{interval}" + filter_datasets datasets, included_excluded_datasets, "#{snapshot_property}:#{interval}" extra_eligible # Gather all of the datasets without an override - filter_datasets datasets, included_excluded_datasets, snapshot_property + filter_datasets datasets, included_excluded_datasets, snapshot_property extra_eligible ### Determine which datasets can be snapshotted recursively and which not datasets = find_recursive_datasets included_excluded_datasets From 95ac14ff09604c6cd8733bfb63142c5062906fa2 Mon Sep 17 00:00:00 2001 From: Lenz Weber Date: Mon, 14 Feb 2022 20:12:40 +0100 Subject: [PATCH 3/3] fixup --- lib/zfstools.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zfstools.rb b/lib/zfstools.rb index 72dcba7..1748c6b 100644 --- a/lib/zfstools.rb +++ b/lib/zfstools.rb @@ -139,9 +139,9 @@ def find_eligible_datasets(interval, pool, extra_eligible = []) } # Gather the datasets given the override property - filter_datasets datasets, included_excluded_datasets, "#{snapshot_property}:#{interval}" extra_eligible + filter_datasets datasets, included_excluded_datasets, "#{snapshot_property}:#{interval}", extra_eligible # Gather all of the datasets without an override - filter_datasets datasets, included_excluded_datasets, snapshot_property extra_eligible + filter_datasets datasets, included_excluded_datasets, snapshot_property, extra_eligible ### Determine which datasets can be snapshotted recursively and which not datasets = find_recursive_datasets included_excluded_datasets