Avoid removing nonexistent snapshots

Store retain_snapshot in JSON and use that to check during delete.
This commit is contained in:
Joshua Boniface 2023-10-24 01:32:18 -04:00
parent 714bde89e6
commit 83b937654c
1 changed files with 10 additions and 8 deletions

View File

@ -1468,6 +1468,7 @@ def backup_vm(
"type": backup_type, "type": backup_type,
"datestring": datestring, "datestring": datestring,
"incremental_parent": incremental_parent, "incremental_parent": incremental_parent,
"retained_snapshot": retain_snapshot,
"vm_detail": vm_detail, "vm_detail": vm_detail,
"backup_files": [ "backup_files": [
(f"{domain}.{datestring}.pvcdisks/{p}.{v}.{export_fileext}", s) (f"{domain}.{datestring}.pvcdisks/{p}.{v}.{export_fileext}", s)
@ -1561,14 +1562,15 @@ def remove_backup(zkhandler, domain, backup_path, datestring):
is_snapshot_remove_failed = False is_snapshot_remove_failed = False
which_snapshot_remove_failed = list() which_snapshot_remove_failed = list()
msg_snapshot_remove_failed = list() msg_snapshot_remove_failed = list()
for volume_file, _ in backup_source_details.get("backup_files"): if backup_source_details["retained_snapshot"]:
pool, volume, _ = volume_file.split("/")[-1].split(".") for volume_file, _ in backup_source_details.get("backup_files"):
snapshot = f"backup_{datestring}" pool, volume, _ = volume_file.split("/")[-1].split(".")
retcode, retmsg = ceph.remove_snapshot(zkhandler, pool, volume, snapshot) snapshot = f"backup_{datestring}"
if not retcode: retcode, retmsg = ceph.remove_snapshot(zkhandler, pool, volume, snapshot)
is_snapshot_remove_failed = True if not retcode:
which_snapshot_remove_failed.append(f"{pool}/{volume}") is_snapshot_remove_failed = True
msg_snapshot_remove_failed.append(retmsg) which_snapshot_remove_failed.append(f"{pool}/{volume}")
msg_snapshot_remove_failed.append(retmsg)
# 3. Remove files # 3. Remove files
is_files_remove_failed = False is_files_remove_failed = False