From aaf1329db505b567377f938214ae4df79e2f5990 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 19 Feb 2022 18:38:57 +0100 Subject: zfssnap: ... --- modules/zfssnap/zfssnap.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/zfssnap/zfssnap.py b/modules/zfssnap/zfssnap.py index 69ab1ae6..e90ed0db 100644 --- a/modules/zfssnap/zfssnap.py +++ b/modules/zfssnap/zfssnap.py @@ -73,11 +73,15 @@ def prune(config, dry_run, keep_newest): keep = set() kept_count = defaultdict(lambda: defaultdict(lambda: 0)) + KeptBecause = namedtuple('KeptBecause', ['rule', 'ix', 'base', 'period']) + kept_because = OrderedDict(deque) def keep_because(base, snap, rule, period=None): nonlocal kept_count if snap not in keep: kept_count[rule][base] += 1 - logger.info(f'Keeping ‘{snap}’ because of rule ‘{rule}’ (#{kept_count[rule][base]} for ‘{base}’, period={period})') + if snap not in kept_because: + kept_because[snap] = deque() + kept_because[snap].append(KeptBecause(rule=rule, ix=kept_count[rule][base], base=base, period=period)) keep.add(snap) within = config.gettimedelta('KEEP', 'within') @@ -136,6 +140,9 @@ def prune(config, dry_run, keep_newest): if to_keep > 0: logger.debug(f'Missing {to_keep} to fulfill {rule}={desired_count} for ‘{base}’') + for snap, reasons in kept_because: + reasons_str = ', '.join(map(str, reasons)) + logger.info(f'Keeping ‘{snap}’ because: {reasons_str}') all_snaps = {snap.name for _, snaps in items.items() for snap in snaps} to_destroy = all_snaps - keep if not to_destroy: -- cgit v1.2.3