Skip to content

Instantly share code, notes, and snippets.

@barinek
Created January 5, 2010 18:30
Show Gist options
  • Save barinek/269580 to your computer and use it in GitHub Desktop.
Save barinek/269580 to your computer and use it in GitHub Desktop.
aws snapshots with capistrano
require 'aws'
namespace :aws do
task :create_snapshot do
instances.each do |instance|
ec2 = ec2_connect
volume_ids = find_volume_ids_for_instance(instance)
if volume_ids
volume_ids.each do |volume_id|
logger.debug("Creating snapshot for volume id #{volume_id}")
ec2.create_snapshot( :volume_id => volume_id )
end
else
logger.debug("Unable to find volume ids for #{instance}")
end
end
end
def find_volume_ids_for_instance(instance)
...
end
def config_file
conf_file = Pathname.new "#{ENV["HOME"]}/aws.yml"
return conf_file if conf_file.exist?
raise "Unable to locate aws.yml file"
end
def conf
@conf ||= YAML.load(open(config_file))
end
def ec2_connect
AWS::EC2::Base.new(:access_key_id => conf['key_id'], :secret_access_key => conf['secret_key'])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment