FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

nasbackup.sh: add optional backup compression via -c flag by jmsperu · Pull Request #12844 · apache/cloudstack · GitHub

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .sh  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
24 changes: 22 additions & 2 deletions scripts/vm/hypervisor/kvm/nasbackup.sh
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ NAS_ADDRESS=""
MOUNT_OPTS=""
BACKUP_DIR=""
DISK_PATHS=""
COMPRESS=""
logFile="/var/log/cloudstack/agent/agent.log"

log() {
Expand Down Expand Up @@ -112,6 +113,21 @@ backup_running_vm() {
sleep 5
done
rm -f $dest/backup.xml

# Compress backup files if requested
if [[ "$COMPRESS" == "true" ]]; then
log -ne "Compressing backup files for $VM"
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
mv "$tmp_img" "$img"
else
log -ne "Warning: compression failed for $img, keeping uncompressed"
rm -f "$tmp_img"
fi
done
fi
sync

# Print statistics
Expand All @@ -131,7 +147,7 @@ backup_stopped_vm() {
name="root"
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"
name="datadisk"
done
sync
Expand Down Expand Up @@ -165,7 +181,7 @@ mount_operation() {

function usage {
echo ""
echo "Usage: $0 -o <operation> -v|--vm <domain name> -t <storage type> -s <storage address> -m <mount options> -p <backup path> -d <disks path>"
echo "Usage: $0 -o <operation> -v|--vm <domain name> -t <storage type> -s <storage address> -m <mount options> -p <backup path> -d <disks path> [-c]"
echo ""
exit 1
}
Expand Down Expand Up @@ -207,6 +223,10 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
-c|--compress)
COMPRESS="true"
shift
;;
-h|--help)
usage
shift
Expand Down
Loading

Back | FazBrowse Home | New Git URL