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.
This commit is contained in:
Joshua Boniface 2024-02-02 09:31:16 -05:00
parent 18f09196be
commit c473dcca81
1 changed files with 4 additions and 14 deletions

View File

@ -246,6 +246,8 @@ def vm_autobackup(
Perform automatic backups of VMs based on an external config file. Perform automatic backups of VMs based on an external config file.
""" """
backup_summary = dict()
if email_report is not None: if email_report is not None:
from email.utils import formatdate from email.utils import formatdate
from socket import gethostname from socket import gethostname
@ -553,6 +555,8 @@ def vm_autobackup(
with open(autobackup_state_file, "w") as fh: with open(autobackup_state_file, "w") as fh:
jdump(state_data, fh) jdump(state_data, fh)
backup_summary[vm] = tracked_backups
if autobackup_config["auto_mount_enabled"]: if autobackup_config["auto_mount_enabled"]:
# Execute each unmount_cmds command in sequence # Execute each unmount_cmds command in sequence
for cmd in autobackup_config["unmount_cmds"]: for cmd in autobackup_config["unmount_cmds"]:
@ -588,20 +592,6 @@ def vm_autobackup(
if email_report is not None: if email_report is not None:
echo(CLI_CONFIG, "") echo(CLI_CONFIG, "")
echo(CLI_CONFIG, f"Sending email summary report to {email_report}") 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() current_datetime = datetime.now()
email_datetime = formatdate(float(current_datetime.strftime("%s"))) email_datetime = formatdate(float(current_datetime.strftime("%s")))