Skip to content

nasbackup.sh: add optional backup compression via -c flag#12844

Closed
jmsperu wants to merge 1 commit intoapache:4.20from
jmsperu:fix/nasbackup-compression-toggle
Closed

nasbackup.sh: add optional backup compression via -c flag#12844
jmsperu wants to merge 1 commit intoapache:4.20from
jmsperu:fix/nasbackup-compression-toggle

Conversation

@jmsperu
Copy link

@jmsperu jmsperu commented Mar 17, 2026

Summary

  • Add -c/--compress flag to produce compressed qcow2 backup files, reducing NAS storage usage
  • For stopped VMs: passes -c to qemu-img convert directly (single pass, no extra I/O)
  • For running VMs: re-compresses push backup output with qemu-img convert -c after backup completes
  • Compression is off by default to preserve existing behavior

Motivation

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 -c flag can be passed by the CloudStack agent when the admin enables compression in the backup repository settings, giving per-repository control.

Test plan

  • Backup stopped VM without -c — verify identical behavior to current
  • Backup stopped VM with -c — verify compressed qcow2 output (check with qemu-img info)
  • Backup running VM with -c — verify post-backup compression, smaller file sizes
  • Verify compression failure on one disk doesn't abort backup (keeps uncompressed copy)

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 <[email protected]>
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 16.25%. Comparing base (61afb4c) to head (9398d2d).
⚠️ Report is 4 commits behind head on 4.20.

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     
Flag Coverage Δ
uitests 4.15% <ø> (ø)
unittests 17.10% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/--compress CLI flag and wires it into the backup workflow.
  • For stopped VMs, conditionally adds -c to qemu-img convert.
  • For running VMs, performs a post-backup recompression pass over generated .qcow2 files.

💡 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"
@abh1sar
Copy link
Contributor

abh1sar commented Mar 24, 2026

Please see #12848 (comment)

jmsperu added a commit to jmsperu/cloudstack that referenced this pull request Mar 26, 2026
… integrity check

Adds four optional features to NAS backup operations, configurable at
zone scope via CloudStack global settings:

- Compression (-c): qcow2 internal compression of backup files
  Config: nas.backup.compression.enabled (default: false)

- LUKS Encryption (-e): encrypt backup files at rest using qemu-img
  Config: nas.backup.encryption.enabled (default: false)
  Config: nas.backup.encryption.passphrase (Secure category)

- Bandwidth Throttle (-b): limit backup I/O bandwidth via virsh
  blockjob for running VMs or qemu-img -r for stopped VMs
  Config: nas.backup.bandwidth.limit.mbps (default: 0/unlimited)

- Integrity Check (--verify): qemu-img check after backup creation
  Config: nas.backup.integrity.check (default: false)

All features are disabled by default and fully backward compatible.
Settings are read from zone-scoped ConfigKeys in NASBackupProvider,
passed to the KVM agent via TakeBackupCommand details map, and
translated to nasbackup.sh CLI flags in LibvirtTakeBackupCommandWrapper.

Changes:
- nasbackup.sh: add -c, -b, -e, --verify flags with encrypt_backup()
  and verify_backup() helper functions
- TakeBackupCommand.java: add details map for passing config to agent
- NASBackupProvider.java: add 5 ConfigKeys, populate command details
- LibvirtTakeBackupCommandWrapper.java: extract details, build CLI args,
  handle passphrase temp file lifecycle

Combines and supersedes PRs apache#12844, apache#12846, apache#12848, apache#12845
@jmsperu
Copy link
Author

jmsperu commented Mar 26, 2026

Superseded by #12898 which combines this with the other nasbackup enhancement PRs and adds the Java management server changes requested by @abh1sar in #12848.

@jmsperu jmsperu closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants