From 82a4af05ef32af4bd31ed62ccd51eca05f88d5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Mon, 11 Mar 2024 16:26:14 +0100 Subject: [PATCH] Fix backup script removing image after unsuccessful pivot If pivoting the VM backing storage back to the original image fails (e.g. VM being down at that time), the script currently still deletes the hotswap image, which means that all changes since the creation of the hotswap image are lost. --- site-cookbooks/kosmos_kvm/files/backup_vm.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/site-cookbooks/kosmos_kvm/files/backup_vm.sh b/site-cookbooks/kosmos_kvm/files/backup_vm.sh index 3cf7a39..5b6fe07 100644 --- a/site-cookbooks/kosmos_kvm/files/backup_vm.sh +++ b/site-cookbooks/kosmos_kvm/files/backup_vm.sh @@ -22,8 +22,5 @@ borg create -v $REPOSITORY::$1_$(date +%F_%H-%M) \ /var/lib/libvirt/images/$1.qcow2 \ /root/backups/vm_meta/$1.xml -echo "Pivoting base image back to original" -virsh blockcommit $1 vda --pivot --base=/var/lib/libvirt/images/$1.qcow2 - -echo "Removing snapshot image" -rm /var/lib/libvirt/images/$1.hotswap.qcow2 +echo "Pivoting base image back to original, and removing the snapshot image" +virsh blockcommit $1 vda --pivot --base=/var/lib/libvirt/images/$1.qcow2 && rm /var/lib/libvirt/images/$1.hotswap.qcow2