Very Simple EC2 Snapshot Management

Posted on Fri 01 April 2011 in Tech

I've been pulling my hair out trying to get a handy ec2 snapshot backup/management working. My google results have ranged from broken libraries to using bash scripts to do one aspect and php scripts to do another, all of the solutions seem to have serious issues with regions.

Anyway I've coded up a very very stupidly simple bash script that's based on the ec2-api-tools. Ubuntu based info here. Essentially sudo apt-get install ec2-api-tools should get the required tools.

What it does: Backs up all instances and deletes all snapshots older than 7 days.

You can find it here, hope it helps.

Due to major problems with ec2-api-tools I've done a quick rewrite for to support euca2ools. Essentially I had this script running on a micro instance and due to bugs with the ubuntu kernel and java it would tank my server so I've switched to the python-based euca2ools.

You can find this script here.

To get euca2ools work simply install via sudo apt-get install euca2ools and add this to ~/.eucarc

EC2_REGION="${EC2_REGION:-eu-west-1}"

EC2_CERT=${HOME}/cert.pem

EC2_PRIVATE_KEY=${HOME}/pk.pem

EC2_ACCESS_KEY=AAAAAAAAAAAAAAAAAAA

EC2_SECRET_KEY=+AAAAAAAAAAAAAAaaaaaaaaaaa

EC2_USER_ID=1234567890

EUCALYPTUS_CERT=/etc/ec2/amitools/cert-ec2.pem

EC2_URL=https://ec2.${EC2_REGION}.amazonaws.com

S3_URL=https://s3.amazonaws.com:443