Last active
December 17, 2015 21:09
-
-
Save d6e/5672324 to your computer and use it in GitHub Desktop.
For migrating vm's from one hypervisor to the next.
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
#!/bin/bash | |
if test "$1" == "" ; then | |
echo "### Usage ###" | |
echo "migrate.sh <domain> <user@remotehost>" | |
exit | |
fi | |
if [[ $(virsh list | egrep -o $1) != "" ]] | |
then | |
echo "The domain is currently running, attempting to shutdown" | |
virsh shutdown $1 | |
sleep 10 | |
# If domain doesn't shutdown, force it | |
if [[ $(virsh list | egrep -o $1) != "" ]] | |
then | |
echo "The domain is being stubborn so I'm killing it" | |
virsh destroy $1 | |
fi | |
fi | |
rhost=$(echo $2 | egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}") | |
rsync -az --sparse --progress /var/lib/libvirt/images/$1.img $2:/var/lib/libvirt/images/ | |
virsh dumpxml $1 > $1.xml | |
virsh -c qemu+ssh://$rhost/system define $1.xml | |
rm $1.xml | |
echo "$1 has been migrated to $rhost" | |
echo "starting domain on remote host... " | |
virsh -c qemu+ssh://$rhost/system start $1 | |
echo "removing old domain..." | |
virsh undefine $1 | |
rm /var/lib/libvirt/images/$1.img | |
echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment