Skip to content

Instantly share code, notes, and snippets.

@tsabat
Last active December 23, 2015 06:59
Show Gist options
  • Save tsabat/6598014 to your computer and use it in GitHub Desktop.
Save tsabat/6598014 to your computer and use it in GitHub Desktop.
detach and mount volume

##Inside the instance

Make sure you're not in the volume, as that will prevent the detachment

cd ~

then grep for anything active on that instance

sudo lsof | grep /vol

then unmount all your mounts related to mysql

umount /var/log/mysql
umount /var/lib/mysql
umount /etc/mysql
umount /vol

and stop/kill anything related to that device

##From your command line tools

TAG='tag_name_here'
RSLT=`ec2-describe-instances --filter "tag:Name=$TAG" | grep 'INSTANCE\|sdf'`
INSTANCE_ID=`echo $RSLT | head -n 1 | awk '{print $2}'`
OLD_VOLUME_ID=`echo $RSLT | tail -n 1 | awk '{print $3}'`
ec2-detach-volume $OLD_VOLUME_ID -i $INSTANCE_ID -d '/dev/sdf'

SNAP_ID=`ec2-describe-snapshots -o self --filter 'description=*mysql-master*' | grep completed | sort -r -k4 | head -n 1 | awk '{print $2}'`

NEW_VOLUME_ID=`ec2-create-volume -s 40 -z us-west-2c -t io1 -iops 400 --snapshot $SNAP_ID | awk '{print $2}'`

Now run the following command until the volume is listed as "available"

ec2-describe-volumes $NEW_VOLUME_ID

Then attach it

ec2-attach-volume $NEW_VOLUME_ID -i $INSTANCE_ID -d /dev/sdf

And make sure it's attached:

ec2-describe-volumes $NEW_VOLUME_ID

##Back on the instance

mount -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment