-
-
Save ncr/347519 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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