Created
January 9, 2013 07:15
-
-
Save shaon/960aeb495ab8b29f97c0 to your computer and use it in GitHub Desktop.
keep both ea.exp and ea_cloud.sh in the same directory. ssh keys authorized on new CLC host
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/sh | |
if [ "$*" == "" ] | |
then | |
echo "Usage: $0 <instance id> <new cloud ip>" | |
exit 1 | |
fi | |
if [ "$2" == "" ] | |
then | |
echo "Usage: $0 <instance id> <new cloud ip>" | |
exit 1 | |
fi | |
source .euca/eucarc | |
NEWHOST=$2 | |
euca-describe-volumes | grep i-C15E3B45 | cut -f2 | xargs euca-describe-volumes | grep VOLUME | grep -v snap | cut -f2 > temp_vol_list | |
for x in `euca-describe-volumes | grep i-C15E3B45 | cut -f2 | xargs euca-describe-volumes | grep VOLUME | grep -v snap | cut -f2`; do euca-detach-volume $x; done | |
for x in `cat temp_vol_list`; | |
do | |
STATE=$(euca-describe-volumes $x | grep VOLUME | cut -f6) | |
while [ $STATE != "available" ] | |
do | |
echo $x is $STATE | |
sleep 5 | |
STATE=$(euca-describe-volumes $x | grep VOLUME | cut -f6) | |
done | |
echo $x is $STATE | |
done | |
STOPINSTANCE=$(euca-stop-instances $1) | |
STATE=$(euca-describe-instances $1 | grep INSTANCE | cut -f6) | |
while [ $STATE != "stopped" ] | |
do | |
echo "$1 is stopping" | |
sleep 5 | |
STATE=$(euca-describe-instances $1 | grep INSTANCE | cut -f6) | |
done | |
echo "Stopped" | |
# creating snapshot of the instance | |
echo "Creating snapshot of the instance..." | |
DATAVOLID=$(euca-describe-volumes | grep $1 | cut -f2) | |
DATASNAPID=$(euca-create-snapshot $DATAVOLID | cut -f2) | |
STATE=$(euca-describe-snapshots $DATASNAPID | cut -f4) | |
while [ $STATE != "completed" ] | |
do | |
echo $DATASNAPID is $STATE | |
sleep 10 | |
STATE=$(euca-describe-snapshots $DATASNAPID | cut -f4) | |
done | |
echo $DATASNAPID is $STATE | |
# creating dummy volume and snapshot on the new cloud | |
echo "Creating dummy volume on the new cloud..." | |
NEWVOLSIZE=$(euca-describe-volumes | grep $1 | cut -f2 | xargs euca-describe-volumes | grep VOLUME | cut -f3) | |
NEWVOLID=$(ssh root@$NEWHOST source .euca/eucarc; euca-create-volume -s $NEWVOLSIZE -z oldcloud | cut -f2) | |
STATE=$(ssh root@$NEWHOST source .euca/eucarc; euca-describe-volumes $NEWVOLID | cut -f6) | |
while [ $STATE != "available" ] | |
do | |
echo $NEWVOLID is $STATE | |
sleep 5 | |
STATE=$(ssh root@$NEWHOST source .euca/eucarc; euca-describe-volumes $NEWVOLID | cut -f6) | |
done | |
echo "$NEWVOLID is $STATE" | |
echo "creating dummy snapshot on the new cloud..." | |
DUMMYSNAPID=$(ssh root@$NEWHOST source .euca/eucarc; euca-create-snapshot $NEWVOLID | cut -f2) | |
STATE=$(ssh root@$NEWHOST source .euca/eucarc; euca-describe-snapshots $DUMMYSNAPID | cut -f4) | |
while [ $STATE != "completed" ] | |
do | |
echo $DUMMYSNAPID is $STATE | |
sleep 10 | |
STATE=$(ssh root@$NEWHOST source .euca/eucarc; euca-describe-snapshots snap-064D3D83 | cut -f4) | |
done | |
echo $DUMMYSNAPID is $STATE | |
# deleting dummy volume from the new cloud | |
echo "deleting dummy volume from the new cloud..." | |
euca-delete-volume $NEWVOLID | |
./ea.exp grpadmin zoomzoom 192.168.7.189 $DATASNAPID $DUMMYSNAPID | |
read -p "Write your EMI name: " NEWEMI | |
ssh root@$NEWHOST source .euca/eucarc; euca-register -a x86_64 -n $NEWEMI --root-device-name /dev/vda -b/dev/vda=$DUMMYSNAPID | |
sleep 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment