Skip to content

Instantly share code, notes, and snippets.

@jasonpincin
Created February 13, 2013 16:42
Show Gist options
  • Save jasonpincin/4945946 to your computer and use it in GitHub Desktop.
Save jasonpincin/4945946 to your computer and use it in GitHub Desktop.
Moves a SmartOS VM to a different SmartOS host
#!/usr/bin/bash
# Moves a SmartOS VM to a different host
# This script stops the VM, sends it to the target host,
# imports it on the target host, and starts it on the
# target host. It is your responsibility to remove it on
# the origin host after confirming the script worked as
# expected.
#
# Usage:
# vmmv <uuid> <target host>
#
REACHABLE=0
ping $2 > /dev/null 2>&1 && REACHABLE=1
if [ $REACHABLE -eq 1 ]; then
echo "Stopping $1..."
vmadm stop $1 > /dev/null 2>&1
echo "Sending $1 to $2..."
vmadm send $1 | ssh $2 'cat | vmadm receive'
echo "Starting $1 on $2..."
ssh $2 "vmadm start $1"
echo "VM migration complete."
echo ""
echo "Don't forget to remove the local copy of this VM after"
echo "verifying the migration was successful."
echo ""
echo "Next step (BE CAREFUL):"
echo " vmadm delete $1"
echo ""
else
echo "Target host is unreachable."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment