nasbackup.sh: add optional backup compression via -c flag#12844
Open
jmsperu wants to merge 1 commit intoapache:4.20from
Open
nasbackup.sh: add optional backup compression via -c flag#12844jmsperu wants to merge 1 commit intoapache:4.20from
jmsperu wants to merge 1 commit intoapache:4.20from
Conversation
Add -c/--compress flag that produces compressed qcow2 backup files, reducing storage usage on the NAS backup target. For stopped VMs: passes -c to qemu-img convert directly. For running VMs: re-compresses push backup output with qemu-img convert -c after the backup job completes. Compression is off by default to preserve existing behavior and avoid increased CPU usage on hosts that don't need it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
03c8e1e to
9398d2d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 4.20 #12844 +/- ##
=========================================
Coverage 16.24% 16.25%
- Complexity 13411 13412 +1
=========================================
Files 5664 5664
Lines 500463 500463
Branches 60779 60779
=========================================
+ Hits 81308 81334 +26
+ Misses 410059 410035 -24
+ Partials 9096 9094 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an optional -c/--compress flag to nasbackup.sh so NAS backups can be written as compressed qcow2 images (default remains uncompressed), reducing backup storage usage.
Changes:
- Introduces
-c/--compressCLI flag and wires it into the backup workflow. - For stopped VMs, conditionally adds
-ctoqemu-img convert. - For running VMs, performs a post-backup recompression pass over generated
.qcow2files.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| for disk in $DISK_PATHS; do | ||
| volUuid="${disk##*/}" | ||
| qemu-img convert -O qcow2 $disk $dest/$name.$volUuid.qcow2 | tee -a "$logFile" | ||
| qemu-img convert $([[ "$COMPRESS" == "true" ]] && echo "-c") -O qcow2 $disk $dest/$name.$volUuid.qcow2 | tee -a "$logFile" |
| for img in "$dest"/*.qcow2; do | ||
| [[ -f "$img" ]] || continue | ||
| local tmp_img="${img}.tmp" | ||
| if qemu-img convert -c -O qcow2 "$img" "$tmp_img" 2>&1 | tee -a "$logFile"; then |
| [[ -f "$img" ]] || continue | ||
| local tmp_img="${img}.tmp" | ||
| if qemu-img convert -c -O qcow2 "$img" "$tmp_img" 2>&1 | tee -a "$logFile"; then | ||
| mv "$tmp_img" "$img" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
-c/--compressflag to produce compressed qcow2 backup files, reducing NAS storage usage-ctoqemu-img convertdirectly (single pass, no extra I/O)qemu-img convert -cafter backup completesMotivation
NAS backup storage fills up quickly with large VM disks. qcow2 compression typically achieves 40-60% size reduction with minimal CPU overhead, extending backup retention without additional storage.
The
-cflag can be passed by the CloudStack agent when the admin enables compression in the backup repository settings, giving per-repository control.Test plan
-c— verify identical behavior to current-c— verify compressed qcow2 output (check withqemu-img info)-c— verify post-backup compression, smaller file sizes