From c473dcca816dd592acf62edf14b1224e09915df2 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 2 Feb 2024 09:31:16 -0500 Subject: [PATCH] Fix errors with autobackup email summary How this was being done didn't work, as the backup volume was already unmounted when we tried to read the backups from it. Instead, populate the backup summary earlier in the run, during the actual backup. --- client-cli/pvc/cli/helpers.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/client-cli/pvc/cli/helpers.py b/client-cli/pvc/cli/helpers.py index 24164334..c8ce2137 100644 --- a/client-cli/pvc/cli/helpers.py +++ b/client-cli/pvc/cli/helpers.py @@ -246,6 +246,8 @@ def vm_autobackup( Perform automatic backups of VMs based on an external config file. """ + backup_summary = dict() + if email_report is not None: from email.utils import formatdate from socket import gethostname @@ -553,6 +555,8 @@ def vm_autobackup( with open(autobackup_state_file, "w") as fh: jdump(state_data, fh) + backup_summary[vm] = tracked_backups + if autobackup_config["auto_mount_enabled"]: # Execute each unmount_cmds command in sequence for cmd in autobackup_config["unmount_cmds"]: @@ -588,20 +592,6 @@ def vm_autobackup( if email_report is not None: echo(CLI_CONFIG, "") echo(CLI_CONFIG, f"Sending email summary report to {email_report}") - backup_summary = dict() - for vm in backup_vms: - backup_path = f"{backup_suffixed_path}/{vm}" - autobackup_state_file = f"{backup_path}/.autobackup.json" - if not path.exists(backup_path) or not path.exists(autobackup_state_file): - # There are no new backups so the list is empty - state_data = dict() - tracked_backups = list() - else: - with open(autobackup_state_file) as fh: - state_data = jload(fh) - tracked_backups = state_data["tracked_backups"] - - backup_summary[vm] = tracked_backups current_datetime = datetime.now() email_datetime = formatdate(float(current_datetime.strftime("%s")))