-
Notifications
You must be signed in to change notification settings - Fork 1.3k
KVM NAS backup: resume VM and exit on backup failure #12872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.22
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -141,7 +141,8 @@ backup_running_vm() { | |||||
| break ;; | ||||||
| Failed) | ||||||
| echo "Virsh backup job failed" | ||||||
| cleanup ;; | ||||||
| cleanup | ||||||
| exit 1 ;; | ||||||
| esac | ||||||
| sleep 5 | ||||||
| done | ||||||
|
|
@@ -177,6 +178,7 @@ backup_stopped_vm() { | |||||
| if ! qemu-img convert -O qcow2 "$disk" "$output" > "$logFile" 2> >(cat >&2); then | ||||||
| echo "qemu-img convert failed for $disk $output" | ||||||
| cleanup | ||||||
| exit 1 | ||||||
| fi | ||||||
| name="datadisk" | ||||||
| done | ||||||
|
|
@@ -221,6 +223,20 @@ mount_operation() { | |||||
| cleanup() { | ||||||
| local status=0 | ||||||
|
|
||||||
| # Resume the VM if it was paused (e.g. by virsh backup-begin) | ||||||
| if [[ -n "$VM" ]]; then | ||||||
| local vm_state | ||||||
| vm_state=$(virsh -c qemu:///system domstate "$VM" 2>/dev/null) | ||||||
| if [[ "$vm_state" == "paused" ]]; then | ||||||
|
||||||
| if [[ "$vm_state" == "paused" ]]; then | |
| if [[ "$vm_state" == paused* ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
set -eo pipefailenabled,vm_state=$(virsh ... domstate ...)will causecleanup()to exit immediately ifvirsh domstatereturns non-zero (e.g., VM not found / libvirt transient error), which can prevent unmount/removal and also skip the resume attempt. Please make thedomstateprobe non-fatal (e.g., allow failure and treat state as empty) so cleanup always completes best-effort.