Created
September 25, 2012 03:33
-
-
Save nthj/3779827 to your computer and use it in GitHub Desktop.
Quickly dump your latest Heroku backup into Rackspace Cloud Files via rake db:backup
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
namespace :db do | |
desc 'Copy latest Heroku backup over to our Rackspace account' | |
task backup: :environment do | |
require 'heroku/client/pgbackups' | |
require 'open-uri' | |
credentials = YAML::load_file(Rails.root.join('config', 'rackspace.yml')) | |
api_key = credentials['production']['api_key'] | |
container = credentials['production']['container'] | |
username = credentials['production']['username'] | |
url = Heroku::Client::Pgbackups.new(ENV['PGBACKUPS_URL']).get_latest_backup['public_url'] | |
open('tmp/backup.dump', 'wb') do |file| | |
file << open(url).read | |
end | |
etag = `md5sum tmp/backup.dump`.to_s.split(' ').first | |
_, destination, token = ` curl -D - \ | |
-H "X-Auth-Key: #{api_key}" \ | |
-H "X-Auth-User: #{username}" \ | |
https://auth.api.rackspacecloud.com/v1.0 | grep "X-"`.split("\n").map(&:strip).delete_if(&:blank?).map do |key| | |
key.split(' ').last | |
end | |
puts command = <<COMMAND | |
curl -X PUT -T tmp/backup.dump \ | |
-H "ETag: #{etag}" \ | |
-H "X-Auth-Token: #{token}" \ | |
#{destination}/#{container}/backup-#{Time.now.to_i}.dump | |
COMMAND | |
`#{command}` | |
end | |
end |
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
gem 'heroku' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment