Here is a very simple script I wrote to create snapshots of all attached EBS volumes for a specific instance. I call this script via Cron on a regular basis. The script is available for download at http://pastie.org/3027416 You will need to have the Amazon EC2 API Tools installed on the same machine this script is executed from.

 

#!/bin/bash
#
# Created by Jason Buscema <jbuscema@lambesis.com>
#
# Create snapshots of the attached EBS volumes for a specific instance. Script
# will look for ALL volumes assigned to an instance and create snapshots of
# them.
# You will need to have the Amazon EC2 command line tools installed in
# order for this script to work. Get them from http://aws.amazon.com/developertools/351

# Usage
# Call this script with an instance name and a readable name. IE:
# ./backup-s3.sh [instance] [readable name]
# ./backup-s3.sh i-123456 MyServer

# Define our exports we'll need for the tools to work. There are better
# ways of doing this.
export EC2_HOME=/root/.ec2
export PATH=$PATH:$EC2_HOME/bin
export EC2_PRIVATE_KEY=$EC2_HOME/pk-myprivatekeynamegoeshere.pem
export EC2_CERT=$EC2_HOME/cert-mycertnamegoeshere.pem
export PATH=~/.ec2/bin:$PATH
export JAVA_HOME=/usr/java/default
export PATH=$PATH:/usr/java/default

# Which instance are working with? Read from stdin
INSTANCE="$1"
DESCR="$2"

if [  $1 -a $2 ]
	then

	# Get attached volumes for specific instance
	TMPFILE="/tmp/`date +%N`"
	ec2-describe-volumes | grep $INSTANCE | awk '{print $2}' > $TMPFILE

	while read line
	do
		echo -e "Creating snapshot for - $DESCR for $INSTANCE from $line (via `hostname`)"
	    ec2-create-snapshot $line -d "$DESCR snap for $INSTANCE from $line (via `hostname`)"
	done < $TMPFILE

	# Remove our tmpfile
	rm -rf $TMPFILE

	exit 1

else
	echo "> ERROR - Need to pass in the instance ID and a name separated by a space. IE: 'backup-s3.sh i-1234567 Name'"
	exit 1
fi