So I posted a snapshot export script on here a long time ago, and it wasn't really correct. It created an overlay disk of a backing store and exported the backing store. Red Hat doesn't include the most up to date version of QEMU, so they can push RHEV. RHEL/CentOS 7 only comes with QEMU 1.5, and for live snapshots you need at least 2.0. So if you ad the oVirt repos you can get the newest version with the package qemu-kvm-rhev
, or use Fedora server. Here's a script I wrote to take a live external snapshot and compress it to a location. I used my normal template with the interactive function. vmLocation is the location of your VMs. I usually keep mine in the same area. I should add full paths for everything, but I'm lazy this evening. I'll add them later. I also need to add some error handling but this is a rough start if anyone needs to use it.
#!/bin/bash
vmLocation="/data/VMs"
today=$(date +%m-%d-%Y)
#Script functions
function script_help () {
echo "
Usage: $(basename $0) [options] dom-name snap-name save-location disk-name
-i Ineractive mode
-h this help text
dom-name Name of domain to take snapshot of
snap-name Name of snapshot
save-location location to copy snapshot to
disk-name Name of disk in VM
Example:
$(basename $0) bind-server bind-snap01 /export/snaps/ vda"
exit ${1:-0}
}
function interactive_snap () {
echo "Domain name"
read name
echo "Snapshot name"
read snap
echo "Location to save snap"
read location
echo "Disk name"
read disk
virsh dumpxml $name > $location/$name.xml
diskPath=$(virsh domblklist $name | grep -i $disk | awk '{ print $2 }')
virsh snapshot-create-as --domain $name $snap --diskspec $disk,file=$vmLocation/$snap.qcow2 --disk-only --atomic
tar -czvf $location/$snap-$today.tar.gz $diskPath
virsh blockcommit $name $disk --active --verbose --pivot
rm -f $vmLocation/$snap.qcow2
virsh snapshot-delete --metadata $name $snap
exit ${1:-0}
}
function argument_snap () {
virsh dumpxml $name > $location/$name.xml
diskPath=$(virsh domblklist $name | grep -i $disk | awk '{ print $2 }')
virsh snapshot-create-as --domain $name $snap --diskspec $disk,file=$vmLocation/$snap.qcow2 --disk-only --atomic
tar -czvf $location/$snap-$today.tar.gz $diskPath
virsh blockcommit $name $disk --active --verbose --pivot
rm -f $vmLocation/$snap.qcow2
virsh snapshot-delete --metadata $name $snap
exit ${1:-0}
}
#Show help if no arguments or options are passed
[[ ! "$*" ]] && script_help 1
OPTIND=1
#Read command line options
while getopts "ih" opt; do
case "$opt" in
i) interactive_snap ;;
h) script_help ;;
\?) script_help 1 ;;
esac
done
shift $(($OPTIND-1));
#Run argument function
name=$1
snap=$2
location=$3
disk=$4
argument_snap