Cleanup old EBS snapshots
At Librato we rely on Amazon EBS as part of ourĀ Silverline infrastructure. Accordingly, we periodically snapshot our EBS volumes in case of data loss. I wanted to find a script that would cleanup our sprawl of snapshots that accumulated over time.
A quick search found a number of PHP solutions, but we have stuck with mostly BASH and Ruby for infrastructure scripting so far so we didn’t want another dependency. Anyways, I stumbled across this Ruby script over at ElastDream which did most of what I was looking for. However, I wanted to be able to specify a minimum number of snapshots to keep, regardless of time, so that you can’t accidentally delete all snapshots for a particular volume.
This script supports the following configuration options:
Usage: cleanup_snapshots [options] <volume>
-h, --help Display this screen
--key KEY Amazon access key
--secret KEY Amazon secret key
--days DAYS How many days back to keep (default: 15)
--min KEEP Minimum number of snapshots to keep (default: 5)
--verbose Enable verbose output
--uri URI Use this EC2 URI instead of default (e.g. EU-West)
Find the source below, hope this is helpful for others. ;-)