Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions scripts/vm/hypervisor/kvm/nasbackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ NAS_ADDRESS=""
MOUNT_OPTS=""
BACKUP_DIR=""
DISK_PATHS=""
BANDWIDTH=""
logFile="/var/log/cloudstack/agent/agent.log"

log() {
Expand Down Expand Up @@ -102,6 +103,14 @@ backup_running_vm() {
# Start push backup
virsh -c qemu:///system backup-begin --domain $VM --backupxml $dest/backup.xml > /dev/null 2>/dev/null

# Throttle backup bandwidth if requested (MiB/s per disk)
if [[ -n "$BANDWIDTH" ]]; then
for disk in $(virsh -c qemu:///system domblklist $VM --details 2>/dev/null | awk '/disk/{print$3}'); do
virsh -c qemu:///system blockjob $VM $disk --bandwidth "${BANDWIDTH}" 2>/dev/null || true
done
Comment on lines +106 to +110
log -ne "Backup bandwidth limited to ${BANDWIDTH} MiB/s per disk for $VM"
Comment on lines +108 to +111
fi

# Backup domain information
virsh -c qemu:///system dumpxml $VM > $dest/domain-config.xml 2>/dev/null
virsh -c qemu:///system dominfo $VM > $dest/dominfo.xml 2>/dev/null
Expand Down Expand Up @@ -131,7 +140,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"
ionice -c 3 qemu-img convert $([[ -n "$BANDWIDTH" ]] && echo "-r" "${BANDWIDTH}M") -O qcow2 $disk $dest/$name.$volUuid.qcow2 | tee -a "$logFile"
name="datadisk"
done
sync
Expand Down Expand Up @@ -165,7 +174,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> [-b <MiB/s>]"
echo ""
exit 1
}
Expand Down Expand Up @@ -207,6 +216,11 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
-b|--bandwidth)
BANDWIDTH="$2"
shift
shift
;;
-h|--help)
usage
shift
Expand Down
Loading