Amazon EC2 Consistent Snapshots
Amazon EC2 is the most powerful and customizable cloud based system management tool I’ve used. However nothing is obvious and everything needs to be researched and learned. I should probably start from the beginning, but I won’t, and I’ll start with backups. Lets focus on taking consistent daily snapshots of your data on Amazon and how long we will store them for.
Taking consistent snapshots of Amazon EC2 EBS instances has never been so easy. Thank You Eric Hammond and Erik
Step 1
On Ubuntu, you can install the ec2-consistent-snapshot package using the new Alestic PPA (personal package archive) hosted on Launchpad.net. Here are the steps to set up access to packages in the Alestic PPA and install the software package and its dependencies:
- sudo add-apt-repository ppa:alestic &&
- sudo apt-get update && sudo apt-get install -y ec2-consistent-snapshot
Step 2
Download http://www.thecloudsaga.com/wp-content/uploads/2010/03/ec2-manage-snapshots.zip and uzip into /srv/ec2-snapshots/ This script assumes we are running snapshots daily it keeps snapshots made:
- in the last 7 days
- the past 4 sundays
- every first day of the month
unzip and configure config.ini for your access key, secret key, and region of server
Step 3
Now create a file in /srv/ec2-snapshots/ i.e. take_volume_snapshot.sh to look like
#!/bin/sh
# Takes a snapshot of the EBS volume/s
export EC2_HOME=/usr/bin
KEY_FILE=PUTYOURAWSACCESSKEYHERE
CERT_FILE=PUTYOURSECRETAWSACCESSKEYHERE
export JAVA_HOME=/usr/lib/jvm/default-java
echo "starting weekly snapshots of ew.infomous server volumes..."
$EC2_HOME/ec2-consistent-snapshot --aws-access-key-id $KEY_FILE --aws-secret-access-key $CERT_FILE vol-idnumberfromawsvolumeconsole
#if you have more than one disk on the server
$EC2_HOME/ec2-consistent-snapshot --aws-access-key-id $KEY_FILE --aws-secret-access-key $CERT_FILE vol-idnumberfromawsvolumeconsole
echo "snapshots commands issued"
#Remove old Snapshot Scripts
echo "starting snapshot prune"
/usr/bin/php /srv/ec2-snapshots/ec2-manage-snapshots/bin/ec2-manage-snapshots.php --volume vol-idnumberfromawsvolumeconsole
/usr/bin/php /srv/ec2-snapshots/ec2-manage-snapshots/bin/ec2-manage-snapshots.php --volume vol-idnumberfromawsvolumeconsole
echo "prune completed"
Step 4
Add the scripts to your scheduler
vim /etc/crontab
0 1 * * * root /srv/ec2-snapshots/take_volume_snapshot.sh
which runs every day at 1 am.
Make sure you
chmod u+x /srv/ec2-snapshots/take_volume_snapshot.sh