Earlier I posted a way to cleanup snapshots. I’ve had a few emails asking how I automated the creation. Here is a quick command line (Linux) to automate the creation of the snapshots. Make sure you have your environment setup and the latest version of the EC2 Tools API installed and in the PATH. You can place this command as a cron entry, or simply run it from the command line.
for a in $(ec2-describe-volumes |grep -Ev "ATTACHMENT" |cut -f2);do ec2-create-snapshot $a; done;
All this is doing is grabbing the volume ID’s from the ec2-describe-volumes output – removing the extraneous information, and executing the ec2-create-snapshot command on each volume. The good thing about this is that it doesn’t have to be modified as you add new volumes. Please see my earlier posting on snapshot cleanup to have a full solution from creation to cleanup.
Quick and easy.

{ 4 } Comments
a better tool to use especially if you’re running mysql on any of your instances is the ec2-consistent-backup program. It will freeze your drive and mysql for a couple seconds so you get a clean snapshot that you can safely reload mysql from. Otherwise the binary files can often be corrupted because of database reads/writes happening during the snapshot process.
http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1663
Very true; thanks for the input Doug.
For some reason this isn’t working when I try to run it in cron – it says I need to specify the key and certificate files. I have these environment variables set in my .bashrc , and the command works OK straight from the command line. What do I have to do to get this to work in cron? (sysadmin newb here)
@Phil: The key and cert files here are the x.509 Certificates available here:
AWS Console -> Account -> Security Credentials -> x.509 Certificates
Post a Comment