Skip to content

Instantly share code, notes, and snippets.

@outoftime
Created March 28, 2011 14:31
Show Gist options
  • Save outoftime/890564 to your computer and use it in GitHub Desktop.
Save outoftime/890564 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'
module Backup
module Database
class HerokuPgbackups < Base
attr_accessor :name
def initialize(&block)
instance_eval(&block)
prepare!
end
def perform!
log!
Heroku::Command::Pgbackups.new(['--app', name, '--expire']).capture
backup_url = Heroku::Command::Pgbackups.new(['--app', name]).pgbackup_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