Created
March 9, 2012 22:19
-
-
Save dmreiland/2009020 to your computer and use it in GitHub Desktop.
create, purge EBS snapshots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "rubygems" | |
| require "yaml" | |
| require "syslog" | |
| require "aws-sdk" | |
| class Snapshot | |
| def initialize(config_file) | |
| begin | |
| @config = YAML.load_file(config_file) | |
| @ec2 = AWS::EC2.new(:access_key_id => @config['access_key_id'], :secret_access_key => @config['secret_access_key']) | |
| rescue Exception => e | |
| Syslog.open('snapshot_maintenance') { |log| log.crit("Failed to load configuration file: #{e.message}") } | |
| exit | |
| end | |
| end | |
| def create | |
| @config['volumes'].each { |volume| @ec2.snapshots.create(:volume_id => volume)} | |
| end | |
| def purge | |
| @config['volumes'].each { |volume| | |
| @ec2.snapshots.filter('volume-id', volume).each { |snapshot| | |
| ((Date.today - Date.parse(snapshot.start_time.to_s)).to_i) < @config['max_age'] or snapshot.delete | |
| } | |
| } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment