Created
          January 5, 2010 18:30 
        
      - 
      
- 
        Save barinek/269580 to your computer and use it in GitHub Desktop. 
     aws snapshots with capistrano
  
        
  
    
      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' | |
| 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