From 1c0ed57f1db0317c019375d3db66c5c0f5f94f5c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 19 Feb 2022 18:50:19 +0100 Subject: zfssnap: ... --- modules/zfssnap/default.nix | 2 +- modules/zfssnap/zfssnap.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'modules') diff --git a/modules/zfssnap/default.nix b/modules/zfssnap/default.nix index 1dbd7e17..5093f365 100644 --- a/modules/zfssnap/default.nix +++ b/modules/zfssnap/default.nix @@ -77,7 +77,7 @@ in { ExecStart = let mkSectionName = name: strings.escape [ "[" "]" ] (strings.toUpper name); zfssnapConfig = generators.toINI { inherit mkSectionName; } cfg.config; - in "${zfssnap}/bin/zfssnap -v prune --config=${pkgs.writeText "zfssnap.ini" zfssnapConfig}"; + in "${zfssnap}/bin/zfssnap -v prune --dry-run --config=${pkgs.writeText "zfssnap.ini" zfssnapConfig}"; }; }; 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): continue items[base_name].append(Snap(name=row.name, creation=creation)) - keep = set() kept_count = defaultdict(lambda: defaultdict(lambda: 0)) KeptBecause = namedtuple('KeptBecause', ['rule', 'ix', 'base', 'period']) kept_because = OrderedDict() def keep_because(base, snap, rule, period=None): - nonlocal KeptBecause, keep, kept_count, kept_because + nonlocal KeptBecause, kept_count, kept_because kept_count[rule][base] += 1 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') if within > timedelta(seconds=0): @@ -143,7 +141,7 @@ def prune(config, dry_run, keep_newest): 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 + to_destroy = all_snaps - {*kept_because} if not to_destroy: logger.info('Nothing to prune') -- cgit v1.2.3