Skip to content

Instantly share code, notes, and snippets.

@spinolacastro
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save spinolacastro/659d53a0d3049c73d5cc to your computer and use it in GitHub Desktop.

Select an option

Save spinolacastro/659d53a0d3049c73d5cc to your computer and use it in GitHub Desktop.
#!/bin/bash
source /etc/profile
CMD_CONSISTENT_SNAPSHOT="/usr/local/bin/ec2-consistent-snapshot.pl"
HOSTNAME=$(hostname -s)
if [ "$#" -ne 3 ]; then
echo -e "USAGE: snapshots DATA_DEVICE DATA_DEVICE_MOUNTPOINT..."
exit 1
else
DATA_DEVICE=$1
DATA_DEVICE_MOUNTPOINT=$2
fi
echo -e "Identifying data volume..."
data_volume=$(ec2-describe-volumes --filter "attachment.instance-id=INSTACE-ID" --filter "attachment.device=${DATA_DEVICE}" | grep VOLUME | awk '{print $2}')
if [ "$data_volume" != "" ]; then
echo -e "Identified volume ${data_volume}"
echo -e "Snapshoting data volume with freeze..."
current_date=$(date "+%Y-%m-%d %H:%M:%S")
snapshot_description="$HOSTNAME - $DATA_DEVICE $current_date"
$CMD_CONSISTENT_SNAPSHOT -d --region us-west-1 $data_volume --description "$snapshot_description" --freeze-filesystem $DATA_DEVICE_MOUNTPOINT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment