Skip to content

Instantly share code, notes, and snippets.

@jeremyj
Created October 22, 2014 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyj/e31bd5bd221a1c446591 to your computer and use it in GitHub Desktop.
Save jeremyj/e31bd5bd221a1c446591 to your computer and use it in GitHub Desktop.
Delete stray snapshots
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