diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2022-02-24 14:05:43 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2022-02-24 14:05:43 +0100 |
commit | 9f2dc964bf4e09c712351e176d03dc5f7068528e (patch) | |
tree | d4bc3ca85dfb25bd292a56a4f77e18c4d26076a5 | |
parent | 1a50f2a4d013d8cf12e85b591e216c93e81f2142 (diff) | |
download | nixos-9f2dc964bf4e09c712351e176d03dc5f7068528e.tar nixos-9f2dc964bf4e09c712351e176d03dc5f7068528e.tar.gz nixos-9f2dc964bf4e09c712351e176d03dc5f7068528e.tar.bz2 nixos-9f2dc964bf4e09c712351e176d03dc5f7068528e.tar.xz nixos-9f2dc964bf4e09c712351e176d03dc5f7068528e.zip |
zfssnap: ...
-rw-r--r-- | modules/zfssnap/zfssnap.py | 36 |
1 files changed, 7 insertions, 29 deletions
diff --git a/modules/zfssnap/zfssnap.py b/modules/zfssnap/zfssnap.py index 6d9bc6de..21ed1d5b 100644 --- a/modules/zfssnap/zfssnap.py +++ b/modules/zfssnap/zfssnap.py | |||
@@ -214,31 +214,6 @@ def rename(snapshots, destroy=False, set_is_auto=False): | |||
214 | def autosnap(): | 214 | def autosnap(): |
215 | items = _get_items() | 215 | items = _get_items() |
216 | 216 | ||
217 | recursive, single = set(), set() | ||
218 | |||
219 | for item_name, is_included in items.items(): | ||
220 | if not is_included: | ||
221 | continue | ||
222 | |||
223 | children = {sub_name for sub_name in items if sub_name.startswith(f'{item_name}/')} | ||
224 | is_recursive = all([items[sub_name] for sub_name in children]) | ||
225 | if is_recursive and children: | ||
226 | recursive.add(item_name) | ||
227 | else: | ||
228 | single.add(item_name) | ||
229 | |||
230 | for item_name in recursive | single: | ||
231 | is_covered = any([item_name.startswith(f'{super_name}/') for super_name in recursive]) | ||
232 | if is_covered: | ||
233 | try: | ||
234 | recursive.remove(item_name) | ||
235 | except KeyError: | ||
236 | pass | ||
237 | try: | ||
238 | single.remove(item_name) | ||
239 | except KeyError: | ||
240 | pass | ||
241 | |||
242 | all_snap_names = set() | 217 | all_snap_names = set() |
243 | async def do_snapshot(*snap_items, recursive=False): | 218 | async def do_snapshot(*snap_items, recursive=False): |
244 | nonlocal items, all_snap_names | 219 | nonlocal items, all_snap_names |
@@ -257,11 +232,14 @@ def autosnap(): | |||
257 | _log_cmd(*args) | 232 | _log_cmd(*args) |
258 | subprocess.run(args, check=True) | 233 | subprocess.run(args, check=True) |
259 | 234 | ||
235 | pool_items = defaultdict(set) | ||
236 | for item in items: | ||
237 | pool, _, _ = item.partition('/') | ||
238 | pool_items[pool].add(item) | ||
239 | |||
260 | tasks = [] | 240 | tasks = [] |
261 | if single: | 241 | for snap_items in pool_items.values(): |
262 | tasks.append(do_snapshot(*single)) | 242 | tasks.append(do_snapshot(*snap_items)) |
263 | if recursive: | ||
264 | tasks.append(do_snapshot(*recursive, recursive=True)) | ||
265 | if not tasks: | 243 | if not tasks: |
266 | logger.warning('No snapshots to create') | 244 | logger.warning('No snapshots to create') |
267 | else: | 245 | else: |