From 7d459be8ac08eef15fa4b93eb2c7ec372f9602ac Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 14 Dec 2022 16:57:31 -0800 Subject: [PATCH] group by retention tags when forgetting --- resticbackup/cli.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/resticbackup/cli.py b/resticbackup/cli.py index 57b6b32..f71093d 100644 --- a/resticbackup/cli.py +++ b/resticbackup/cli.py @@ -151,10 +151,17 @@ def cmd_backup(args, parser): env = dict(os.environ) env.update(**config.env) + # the tags in both backup_tags and retention_tags will be added to the backup backup_tags = { - "name": args.name, "host": getfqdn() } + # the tags in retention_tags will be used when pruning backups + retention_tags = { + "name": args.name, + } + + all_tags = dict(retention_tags) + all_tags.update(backup_tags) # perform pre/post-exec # post-exec is executed if the backup fails OR if any pre-exec commands fail @@ -172,7 +179,7 @@ def cmd_backup(args, parser): # run backup backup_cmd = [RESTIC_BIN, "backup", "./"] - for k, v in backup_tags.items(): + for k, v in all_tags.items(): backup_cmd.extend(["--tag", "{}={}".format(k, v)]) for entry in config.backup.exclude: if entry.startswith("/"): @@ -187,7 +194,10 @@ def cmd_backup(args, parser): if not retention_args: return - proc = subprocess.Popen([RESTIC_BIN, "forget"] + retention_args, env=env) + forget_cmd = [RESTIC_BIN, "forget", "--group-by", "tags"] + retention_args + for k, v in retention_tags.items(): + forget_cmd.extend(["--tag", "{}={}".format(k, v)]) + proc = subprocess.Popen(forget_cmd, env=env) proc.communicate(input=None, timeout=None) # perform junk deletion