diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2022-02-20 21:47:54 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2022-02-20 21:47:54 +0100 |
commit | 8c345b32a662cc44a9dd88bb6cf2cfcbfd8c773e (patch) | |
tree | f3580dae56c8db8a057254429666c8d867782f82 | |
parent | 97a779c2ad77fd98873d985abaa73299003d4663 (diff) | |
download | nixos-8c345b32a662cc44a9dd88bb6cf2cfcbfd8c773e.tar nixos-8c345b32a662cc44a9dd88bb6cf2cfcbfd8c773e.tar.gz nixos-8c345b32a662cc44a9dd88bb6cf2cfcbfd8c773e.tar.bz2 nixos-8c345b32a662cc44a9dd88bb6cf2cfcbfd8c773e.tar.xz nixos-8c345b32a662cc44a9dd88bb6cf2cfcbfd8c773e.zip |
zfssnap: async snapshots
-rw-r--r-- | modules/zfssnap/zfssnap.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/modules/zfssnap/zfssnap.py b/modules/zfssnap/zfssnap.py index a8ad231c..b53c6b17 100644 --- a/modules/zfssnap/zfssnap.py +++ b/modules/zfssnap/zfssnap.py | |||
@@ -25,6 +25,8 @@ from functools import cache | |||
25 | 25 | ||
26 | from math import floor | 26 | from math import floor |
27 | 27 | ||
28 | import asyncio | ||
29 | |||
28 | 30 | ||
29 | @cache | 31 | @cache |
30 | def _now(): | 32 | def _now(): |
@@ -234,7 +236,7 @@ def autosnap(): | |||
234 | pass | 236 | pass |
235 | 237 | ||
236 | all_snap_names = set() | 238 | all_snap_names = set() |
237 | def do_snapshot(*snap_items, recursive=False): | 239 | async def do_snapshot(*snap_items, recursive=False): |
238 | nonlocal items, all_snap_names | 240 | nonlocal items, all_snap_names |
239 | snap_names = {_snap_name(item) for item in snap_items} | 241 | snap_names = {_snap_name(item) for item in snap_items} |
240 | if recursive: | 242 | if recursive: |
@@ -251,12 +253,16 @@ def autosnap(): | |||
251 | _log_cmd(*args) | 253 | _log_cmd(*args) |
252 | subprocess.run(args, check=True) | 254 | subprocess.run(args, check=True) |
253 | 255 | ||
256 | tasks = [] | ||
254 | if single: | 257 | if single: |
255 | do_snapshot(*single) | 258 | tasks.append(asyncio.create_task(do_snapshot(*single))) |
256 | if recursive: | 259 | if recursive: |
257 | do_snapshot(*recursive, recursive=True) | 260 | tasks.append(asyncio.create_task(do_snapshot(*recursive, recursive=True))) |
258 | if not single and not recursive: | 261 | if not tasks: |
259 | logger.warning('No snapshots to create') | 262 | logger.warning('No snapshots to create') |
263 | else: | ||
264 | for task in tasks: | ||
265 | await task | ||
260 | for snap in all_snap_names: | 266 | for snap in all_snap_names: |
261 | logger.info(f'Created ‘{snap}’') | 267 | logger.info(f'Created ‘{snap}’') |
262 | if all_snap_names: | 268 | if all_snap_names: |