diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2022-02-19 18:38:57 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2022-02-19 18:38:57 +0100 |
commit | aaf1329db505b567377f938214ae4df79e2f5990 (patch) | |
tree | 38b3ea7d27eb71bdd51f9dceaab896b4d2758fde | |
parent | e3a88254ba32e212ca0e4522454da4e7c4f21f71 (diff) | |
download | nixos-aaf1329db505b567377f938214ae4df79e2f5990.tar nixos-aaf1329db505b567377f938214ae4df79e2f5990.tar.gz nixos-aaf1329db505b567377f938214ae4df79e2f5990.tar.bz2 nixos-aaf1329db505b567377f938214ae4df79e2f5990.tar.xz nixos-aaf1329db505b567377f938214ae4df79e2f5990.zip |
zfssnap: ...
-rw-r--r-- | modules/zfssnap/zfssnap.py | 9 |
1 files changed, 8 insertions, 1 deletions
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): | |||
73 | 73 | ||
74 | keep = set() | 74 | keep = set() |
75 | kept_count = defaultdict(lambda: defaultdict(lambda: 0)) | 75 | kept_count = defaultdict(lambda: defaultdict(lambda: 0)) |
76 | KeptBecause = namedtuple('KeptBecause', ['rule', 'ix', 'base', 'period']) | ||
77 | kept_because = OrderedDict(deque) | ||
76 | def keep_because(base, snap, rule, period=None): | 78 | def keep_because(base, snap, rule, period=None): |
77 | nonlocal kept_count | 79 | nonlocal kept_count |
78 | if snap not in keep: | 80 | if snap not in keep: |
79 | kept_count[rule][base] += 1 | 81 | kept_count[rule][base] += 1 |
80 | logger.info(f'Keeping ‘{snap}’ because of rule ‘{rule}’ (#{kept_count[rule][base]} for ‘{base}’, period={period})') | 82 | if snap not in kept_because: |
83 | kept_because[snap] = deque() | ||
84 | kept_because[snap].append(KeptBecause(rule=rule, ix=kept_count[rule][base], base=base, period=period)) | ||
81 | keep.add(snap) | 85 | keep.add(snap) |
82 | 86 | ||
83 | within = config.gettimedelta('KEEP', 'within') | 87 | within = config.gettimedelta('KEEP', 'within') |
@@ -136,6 +140,9 @@ def prune(config, dry_run, keep_newest): | |||
136 | if to_keep > 0: | 140 | if to_keep > 0: |
137 | logger.debug(f'Missing {to_keep} to fulfill {rule}={desired_count} for ‘{base}’') | 141 | logger.debug(f'Missing {to_keep} to fulfill {rule}={desired_count} for ‘{base}’') |
138 | 142 | ||
143 | for snap, reasons in kept_because: | ||
144 | reasons_str = ', '.join(map(str, reasons)) | ||
145 | logger.info(f'Keeping ‘{snap}’ because: {reasons_str}') | ||
139 | all_snaps = {snap.name for _, snaps in items.items() for snap in snaps} | 146 | all_snaps = {snap.name for _, snaps in items.items() for snap in snaps} |
140 | to_destroy = all_snaps - keep | 147 | to_destroy = all_snaps - keep |
141 | if not to_destroy: | 148 | if not to_destroy: |