Created
October 22, 2014 08:57
-
-
Save jeremyj/e31bd5bd221a1c446591 to your computer and use it in GitHub Desktop.
Delete stray 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 'aws-sdk' | |
KEY = 'xxx' | |
SEC = 'yyy' | |
ec2 = AWS::EC2.new(:access_key_id=> KEY, :secret_access_key=> SEC, :region=> 'eu-west-1') | |
volumes = ec2.volumes.tagged('Backup','backup','BACKUP').tagged_values('true','True','TRUE') | |
snapshots = ec2.snapshots.with_owner(:self).tagged('aws_sm').tagged_values('true') | |
snapshots.each do |snapshot| | |
unless volumes.include?(volumes[snapshot.volume_id]) | |
puts "do you want to delete #{snapshot.id} - #{snapshot.description}?" | |
answer = gets.strip | |
if answer.downcase == "y" | |
snapshot.delete | |
puts "done" | |
else | |
next | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment