From 324c66bb75f7c87f4a141854dbe2f0443bc99a8e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 19 Feb 2022 22:52:50 +0100 Subject: zfssnap: ... --- modules/zfssnap/zfssnap.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/zfssnap/zfssnap.py b/modules/zfssnap/zfssnap.py index 9dcc90a3..281ff586 100644 --- a/modules/zfssnap/zfssnap.py +++ b/modules/zfssnap/zfssnap.py @@ -166,7 +166,7 @@ def prune(config, dry_run, keep_newest): else: logger.info(f'Pruned ‘{snap}’') -def rename(snapshots, destroy=False): +def rename(snapshots, destroy=False, set_is_auto=False): args = ['zfs', 'get', '-H', '-p', '-o', 'name,value', 'creation', *snapshots] _log_cmd(*args) renamed_to = set() @@ -199,6 +199,12 @@ def rename(snapshots, destroy=False): subprocess.run(args, check=True) renamed_to.add(new_name) + if set_is_auto: + logger.info(f'Setting is-auto-snapshot on ‘{new_name}’') + args = ['zfs', 'set', 'li.yggdrasil:is-auto-snapshot=true', new_name] + _log_cmd(*args) + subprocess.run(args, check=True) + def autosnap(): items = _get_items() @@ -286,6 +292,7 @@ def main(): prune_parser.add_argument('--config', '-c', dest='config_files', nargs='*', default=list()) prune_parser.add_argument('--dry-run', '-n', action='store_true', default=False) prune_parser.add_argument('--keep-newest', action='store_true', default=False) + prune_parser.add_argument('--set-is-auto', action='store_true', default=False) prune_parser.set_defaults(cmd=prune) args = parser.parse_args() @@ -297,7 +304,7 @@ def main(): logger.setLevel(logging.DEBUG) cmdArgs = {} - for copy in {'snapshots', 'dry_run', 'destroy', 'keep_newest'}: + for copy in {'snapshots', 'dry_run', 'destroy', 'keep_newest', 'set_is_auto'}: if copy in vars(args): cmdArgs[copy] = vars(args)[copy] if 'config_files' in vars(args): -- cgit v1.2.3