Skip to content

Commit f891dac

Browse files
jmsperuclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 61afb4c commit f891dac

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

scripts/vm/hypervisor/kvm/nasbackup.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@ sanity_checks() {
8484
log -ne "Environment Sanity Checks successfully passed"
8585
}
8686

87+
verify_backup() {
88+
local backup_dir="$1"
89+
local failed=0
90+
for img in "$backup_dir"/*.qcow2; do
91+
[[ -f "$img" ]] || continue
92+
if ! qemu-img check "$img" > /dev/null 2>&1; then
93+
echo "Backup verification failed for $img"
94+
log -ne "Backup verification FAILED: $img"
95+
failed=1
96+
else
97+
log -ne "Backup verification passed: $img"
98+
fi
99+
done
100+
if [[ $failed -ne 0 ]]; then
101+
echo "One or more backup files failed verification"
102+
exit 1
103+
fi
104+
}
105+
87106
### Operation methods ###
88107

89108
backup_running_vm() {
@@ -114,6 +133,8 @@ backup_running_vm() {
114133
rm -f $dest/backup.xml
115134
sync
116135

136+
verify_backup "$dest"
137+
117138
# Print statistics
118139
virsh -c qemu:///system domjobinfo $VM --completed
119140
du -sb $dest | cut -f1
@@ -136,6 +157,8 @@ backup_stopped_vm() {
136157
done
137158
sync
138159

160+
verify_backup "$dest"
161+
139162
ls -l --numeric-uid-gid $dest | awk '{print $5}'
140163
}
141164

0 commit comments

Comments
 (0)