Since the recent outage, I’ve been looking for simple scripts to take a snapshot of a volume and only keep a certain number of these snapshots around. I wanted something that I could run from cron in different intervals for different volumes. I found a few scripts lying around, none of which I really liked so I decided to put together one in ruby.
I created the awstools gem, submitted a patch to amazon-ec2 to allow filter requests on the snapshot api and now I have the tool I was looking for.
Check it out here and let me know what you think.
Until my patch is accepted you’ll have to use my fork of the amazon-ec2 gem. Which means you’ll have to clone it to your machine, build the gem with “gem build amazon-ec2.gemspec” then install that gem with “gem install amazon-ec2…”.
To install awstools
gem install awstools
Or to build it yourself, clone the repo to your machine, and then run:
cd awstools bundle gem build awstools.gemspec gem install awstools-0.0.1.gem
Once installed you can run something like the following from cron:
0 0 * * * snapshots -v volume-id -d "Some Description" -k 2
That will take a snapshot once a day and only keep two snapshots on hand.
Note that there is an -s flag to simulate, so you can see what it will actually do without creating or deleting any snapshots.
If you see all the volumes at amazon fly by, its because you aren’t using my fork of amazon-ec2.