From 83b937654c77acc5abd1ad22b67e7009b4acff03 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 24 Oct 2023 01:32:18 -0400 Subject: [PATCH] Avoid removing nonexistent snapshots Store retain_snapshot in JSON and use that to check during delete. --- daemon-common/vm.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/daemon-common/vm.py b/daemon-common/vm.py index 76178922..9cd0b640 100644 --- a/daemon-common/vm.py +++ b/daemon-common/vm.py @@ -1468,6 +1468,7 @@ def backup_vm( "type": backup_type, "datestring": datestring, "incremental_parent": incremental_parent, + "retained_snapshot": retain_snapshot, "vm_detail": vm_detail, "backup_files": [ (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 which_snapshot_remove_failed = list() msg_snapshot_remove_failed = list() - for volume_file, _ in backup_source_details.get("backup_files"): - pool, volume, _ = volume_file.split("/")[-1].split(".") - snapshot = f"backup_{datestring}" - retcode, retmsg = ceph.remove_snapshot(zkhandler, pool, volume, snapshot) - if not retcode: - is_snapshot_remove_failed = True - which_snapshot_remove_failed.append(f"{pool}/{volume}") - msg_snapshot_remove_failed.append(retmsg) + if backup_source_details["retained_snapshot"]: + for volume_file, _ in backup_source_details.get("backup_files"): + pool, volume, _ = volume_file.split("/")[-1].split(".") + snapshot = f"backup_{datestring}" + retcode, retmsg = ceph.remove_snapshot(zkhandler, pool, volume, snapshot) + if not retcode: + is_snapshot_remove_failed = True + which_snapshot_remove_failed.append(f"{pool}/{volume}") + msg_snapshot_remove_failed.append(retmsg) # 3. Remove files is_files_remove_failed = False