Skip to content

Instantly share code, notes, and snippets.

@edave
Forked from outoftime/config.rb
Created May 10, 2011 02:14
Show Gist options
  • Save edave/963812 to your computer and use it in GitHub Desktop.
Save edave/963812 to your computer and use it in GitHub Desktop.
Support for Heroku pgbackups in Backup library
require './lib/backup/database/heroku_pgbackups.rb'
Backup::Model.new(:heroku, 'Heroku hosted data') do
database Backup::Database::HerokuPgbackups do |db|
db.name = 'my-heroku-app-name'
end
# Followed by other databases, storage, compression, etc.
end
require 'heroku/command'
require "pgbackups/client"
module Backup
module Database
class HerokuPgbackups < Base
attr_accessor :name
def initialize(&block)
instance_eval(&block)
prepare!
end
def perform!
log!
Heroku::Command.load()
backup = Heroku::Command::Pgbackups.new(['DATABASE_URL'],{:app => name, :expire => true})
backup.capture
backup_client_url = ENV["PGBACKUPS_URL"] || backup.heroku.config_vars(backup.app)["PGBACKUPS_URL"]
backup_client = PGBackups::Client.new(backup_client_url)
backup_url = backup_client.get_latest_backup['public_url']
File.open("#{File.join(dump_path, name)}.pgdump", 'w') do |f|
f.binmode
f << Net::HTTP.get(URI.parse(backup_url))
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment