-
-
Save edave/963812 to your computer and use it in GitHub Desktop.
Support for Heroku pgbackups in Backup library
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
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 |
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
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