diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/zfssnap/default.nix | 2 | ||||
-rw-r--r-- | modules/zfssnap/zfssnap.py | 6 |
2 files changed, 3 insertions, 5 deletions
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 { | |||
77 | ExecStart = let | 77 | ExecStart = let |
78 | mkSectionName = name: strings.escape [ "[" "]" ] (strings.toUpper name); | 78 | mkSectionName = name: strings.escape [ "[" "]" ] (strings.toUpper name); |
79 | zfssnapConfig = generators.toINI { inherit mkSectionName; } cfg.config; | 79 | zfssnapConfig = generators.toINI { inherit mkSectionName; } cfg.config; |
80 | in "${zfssnap}/bin/zfssnap -v prune --config=${pkgs.writeText "zfssnap.ini" zfssnapConfig}"; | 80 | in "${zfssnap}/bin/zfssnap -v prune --dry-run --config=${pkgs.writeText "zfssnap.ini" zfssnapConfig}"; |
81 | }; | 81 | }; |
82 | }; | 82 | }; |
83 | 83 | ||
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 | ||