Skip to content

Commit 8550e5a

Browse files
committed
KVM NAS backup: resume VM and exit on backup failure
Fix three bugs in nasbackup.sh that caused VMs to remain paused indefinitely when backup jobs fail (e.g. storage full): 1. Add exit after cleanup on Failed backup job status to prevent infinite polling loop in backup_running_vm() 2. Add exit after cleanup on qemu-img convert failure in backup_stopped_vm() to stop processing subsequent disks 3. Add VM state check and virsh resume to cleanup() so paused VMs are automatically resumed after backup failure Fixes apache#12821
1 parent e93ae1a commit 8550e5a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

scripts/vm/hypervisor/kvm/nasbackup.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ backup_running_vm() {
141141
break ;;
142142
Failed)
143143
echo "Virsh backup job failed"
144-
cleanup ;;
144+
cleanup
145+
exit 1 ;;
145146
esac
146147
sleep 5
147148
done
@@ -177,6 +178,7 @@ backup_stopped_vm() {
177178
if ! qemu-img convert -O qcow2 "$disk" "$output" > "$logFile" 2> >(cat >&2); then
178179
echo "qemu-img convert failed for $disk $output"
179180
cleanup
181+
exit 1
180182
fi
181183
name="datadisk"
182184
done
@@ -221,6 +223,20 @@ mount_operation() {
221223
cleanup() {
222224
local status=0
223225

226+
# Resume the VM if it was paused (e.g. by virsh backup-begin)
227+
if [[ -n "$VM" ]]; then
228+
local vm_state
229+
vm_state=$(virsh -c qemu:///system domstate "$VM" 2>/dev/null)
230+
if [[ "$vm_state" == "paused" ]]; then
231+
if virsh -c qemu:///system resume "$VM" > /dev/null 2>&1; then
232+
log -ne "Resumed VM $VM after backup failure"
233+
else
234+
echo "Failed to resume VM $VM - manual intervention required (virsh resume $VM)"
235+
status=1
236+
fi
237+
fi
238+
fi
239+
224240
rm -rf "$dest" || { echo "Failed to delete $dest"; status=1; }
225241
umount "$mount_point" || { echo "Failed to unmount $mount_point"; status=1; }
226242
rmdir "$mount_point" || { echo "Failed to remove mount point $mount_point"; status=1; }

0 commit comments

Comments
 (0)