From abe881ff40dfc14f4c5a3769e5475b6352c7e6b9 Mon Sep 17 00:00:00 2001 From: dave Date: Fri, 15 Sep 2023 00:18:58 -0700 Subject: [PATCH] separate rentention code --- resticbackup/cli.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/resticbackup/cli.py b/resticbackup/cli.py index 363937b..a160915 100644 --- a/resticbackup/cli.py +++ b/resticbackup/cli.py @@ -13,6 +13,7 @@ def cmd_backup(args, parser): try: run_backup(args.name, config) + run_retention(args.name, config) # update statefile if configured if config.statefile: path = config.statefile.format(name=args.name) @@ -25,16 +26,11 @@ def cmd_backup(args, parser): def run_backup(name, config): - # the tags in both backup_tags and retention_tags will be added to the backup - backup_tags = {} - # the tags in retention_tags will be used when pruning backups - retention_tags = { + # these tags will be added to the backup. They need to match retention_tags in run_rentention, below + backup_tags = { "name": 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 # pre-exec commands failing will stop the backup from being executed @@ -49,7 +45,7 @@ def run_backup(name, config): # run backup backup_cmd = ["backup", "./"] - for k, v in all_tags.items(): + for k, v in backup_tags.items(): backup_cmd.extend(["--tag", "{}={}".format(k, v)]) for entry in config.backup.exclude: if entry.startswith("/"): @@ -58,6 +54,13 @@ def run_backup(name, config): checkp(config.run(backup_cmd)) + +def run_retention(name, config): + # the tags in retention_tags will be used when pruning backups + retention_tags = { + "name": name, + } + # perform retention retention_args = get_retention_args(config.backup.schedule) if retention_args: