summaryrefslogtreecommitdiff
path: root/modules/zfssnap/zfssnap.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/zfssnap/zfssnap.py')
-rw-r--r--modules/zfssnap/zfssnap.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/modules/zfssnap/zfssnap.py b/modules/zfssnap/zfssnap.py
index 32bc4464..96202cf4 100644
--- a/modules/zfssnap/zfssnap.py
+++ b/modules/zfssnap/zfssnap.py
@@ -71,17 +71,15 @@ def prune(config, dry_run, keep_newest):
71 continue 71 continue
72 items[base_name].append(Snap(name=row.name, creation=creation)) 72 items[base_name].append(Snap(name=row.name, creation=creation))
73 73
74 keep = set()
75 kept_count = defaultdict(lambda: defaultdict(lambda: 0)) 74 kept_count = defaultdict(lambda: defaultdict(lambda: 0))
76 KeptBecause = namedtuple('KeptBecause', ['rule', 'ix', 'base', 'period']) 75 KeptBecause = namedtuple('KeptBecause', ['rule', 'ix', 'base', 'period'])
77 kept_because = OrderedDict() 76 kept_because = OrderedDict()
78 def keep_because(base, snap, rule, period=None): 77 def keep_because(base, snap, rule, period=None):
79 nonlocal KeptBecause, keep, kept_count, kept_because 78 nonlocal KeptBecause, kept_count, kept_because
80 kept_count[rule][base] += 1 79 kept_count[rule][base] += 1
81 if snap not in kept_because: 80 if snap not in kept_because:
82 kept_because[snap] = deque() 81 kept_because[snap] = deque()
83 kept_because[snap].append(KeptBecause(rule=rule, ix=kept_count[rule][base], base=base, period=period)) 82 kept_because[snap].append(KeptBecause(rule=rule, ix=kept_count[rule][base], base=base, period=period))
84 keep.add(snap)
85 83
86 within = config.gettimedelta('KEEP', 'within') 84 within = config.gettimedelta('KEEP', 'within')
87 if within > timedelta(seconds=0): 85 if within > timedelta(seconds=0):
@@ -143,7 +141,7 @@ def prune(config, dry_run, keep_newest):
143 reasons_str = ', '.join(map(str, reasons)) 141 reasons_str = ', '.join(map(str, reasons))
144 logger.info(f'Keeping ‘{snap}’ because: {reasons_str}') 142 logger.info(f'Keeping ‘{snap}’ because: {reasons_str}')
145 all_snaps = {snap.name for _, snaps in items.items() for snap in snaps} 143 all_snaps = {snap.name for _, snaps in items.items() for snap in snaps}
146 to_destroy = all_snaps - keep 144 to_destroy = all_snaps - {*kept_because}
147 if not to_destroy: 145 if not to_destroy:
148 logger.info('Nothing to prune') 146 logger.info('Nothing to prune')
149 147