views:

442

answers:

2

I'd expect this to be fairly routine, but cannot find a simple approach for creating an managing EBS snapshots automatically.

Was hoping there'd be a shceduler in the AWS console.. alas not yet.

Would appreciate any suggestions as to how best to do this on from Ubuntu.

Thanks

+2  A: 

You can easily script something to do this for you.

  1. setup the EC2 commandline API tools
  2. set EC2_CERT and EC2_PRIVATE_KEY in order to be able to use the API tools
  3. parse the results of ec2-describe-snapshots
  4. delete the appropriate snapshots

The results look something like:

SNAPSHOT    snap-xxxxxxxx vol-xxxxxxxx completed 2009-08-26T07:39:33+0000 100%

You can then do some parsing of the dates and sorting and start removing the older snapshots.

NOTE: I don't know if we can trust the sort order but I've never seen it sort any other way than oldest to newest.

To delete a snapshot, use ec2-delete-snapshot snap-xxxxxxxx.

The rest I leave to you as a simple Bash script that you can call daily or however often you need from cron.

Matt Todd
A: 

I found this, hope it helps:

ec2-describe-snapshots | sort -r -k 5 | sed 1,6d | awk '{print "Deleting snapshot: " $2}; system("ec2-delete-snapshot " $2)'

See: http://developer.amazonwebservices.com/connect/thread.jspa?messageID=109517

Rodney