From 9f2dc964bf4e09c712351e176d03dc5f7068528e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 24 Feb 2022 14:05:43 +0100 Subject: zfssnap: ... --- modules/zfssnap/zfssnap.py | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) (limited to 'modules/zfssnap/zfssnap.py') 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): def autosnap(): items = _get_items() - recursive, single = set(), set() - - for item_name, is_included in items.items(): - if not is_included: - continue - - children = {sub_name for sub_name in items if sub_name.startswith(f'{item_name}/')} - is_recursive = all([items[sub_name] for sub_name in children]) - if is_recursive and children: - recursive.add(item_name) - else: - single.add(item_name) - - for item_name in recursive | single: - is_covered = any([item_name.startswith(f'{super_name}/') for super_name in recursive]) - if is_covered: - try: - recursive.remove(item_name) - except KeyError: - pass - try: - single.remove(item_name) - except KeyError: - pass - all_snap_names = set() async def do_snapshot(*snap_items, recursive=False): nonlocal items, all_snap_names @@ -257,11 +232,14 @@ def autosnap(): _log_cmd(*args) subprocess.run(args, check=True) + pool_items = defaultdict(set) + for item in items: + pool, _, _ = item.partition('/') + pool_items[pool].add(item) + tasks = [] - if single: - tasks.append(do_snapshot(*single)) - if recursive: - tasks.append(do_snapshot(*recursive, recursive=True)) + for snap_items in pool_items.values(): + tasks.append(do_snapshot(*snap_items)) if not tasks: logger.warning('No snapshots to create') else: -- cgit v1.2.3