Skip to content

Instantly share code, notes, and snippets.

@darkhelmet
Created December 13, 2009 03:54
Show Gist options
  • Save darkhelmet/255263 to your computer and use it in GitHub Desktop.
Save darkhelmet/255263 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'aws/s3'
S3_CREDENTIALS = File.expand_path(File.join('~', '.s3', 'auth.yml'))
APP = 'darkblog'
BUCKET = 's3.blog.darkhax.com'
def bundle
`heroku bundles`.split(/\s/).first
end
def destroy
system("heroku bundles:destroy #{bundle}")
end
def create
system('heroku bundles:capture')
end
def capturing?
!`heroku bundles`.match('capturing').nil?
end
def download
`heroku bundles:download`.split(' ').last
end
def key
Time.now.strftime('%m-%d-%Y-%H-%M.tar.gz')
end
def backup!
destroy
create
print 'Waiting for capture to finish...'
while capturing?
print '.'
sleep(1)
end
print "done!\n"
AWS::S3::Base.establish_connection!(YAML.load_file(S3_CREDENTIALS))
archive = download
File.open(archive, 'rb') do |f|
AWS::S3::S3Object.store("/backups/#{key}", f, BUCKET)
end
print "Done!\n"
end
backup!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment