From f891daca8eb84ee9a17b76cd36c88282e8f417a7 Mon Sep 17 00:00:00 2001 From: jmsperu Date: Tue, 17 Mar 2026 22:22:54 +0300 Subject: [PATCH] nasbackup.sh: verify backup integrity with qemu-img check Add verify_backup() that runs qemu-img check on all qcow2 files after backup completes. Catches corrupt or truncated backup files (e.g. from NFS I/O errors or storage full) before reporting success. Applied to both running and stopped VM backup paths. Co-Authored-By: Claude Opus 4.6 --- scripts/vm/hypervisor/kvm/nasbackup.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/vm/hypervisor/kvm/nasbackup.sh b/scripts/vm/hypervisor/kvm/nasbackup.sh index 9dedaef154a3..98a5c9e67fac 100755 --- a/scripts/vm/hypervisor/kvm/nasbackup.sh +++ b/scripts/vm/hypervisor/kvm/nasbackup.sh @@ -84,6 +84,25 @@ sanity_checks() { log -ne "Environment Sanity Checks successfully passed" } +verify_backup() { + local backup_dir="$1" + local failed=0 + for img in "$backup_dir"/*.qcow2; do + [[ -f "$img" ]] || continue + if ! qemu-img check "$img" > /dev/null 2>&1; then + echo "Backup verification failed for $img" + log -ne "Backup verification FAILED: $img" + failed=1 + else + log -ne "Backup verification passed: $img" + fi + done + if [[ $failed -ne 0 ]]; then + echo "One or more backup files failed verification" + exit 1 + fi +} + ### Operation methods ### backup_running_vm() { @@ -114,6 +133,8 @@ backup_running_vm() { rm -f $dest/backup.xml sync + verify_backup "$dest" + # Print statistics virsh -c qemu:///system domjobinfo $VM --completed du -sb $dest | cut -f1 @@ -136,6 +157,8 @@ backup_stopped_vm() { done sync + verify_backup "$dest" + ls -l --numeric-uid-gid $dest | awk '{print $5}' }