class Heroku::Api::Postgres::Backups

Public Class Methods

new(client) click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 9
def initialize(client)
  @client = client
end

Public Instance Methods

capture(app_id, database_id) click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 36
def capture(app_id, database_id)
  @client.perform_post_request("/client/v11/databases/#{database_id}/backups", {}, host: db_host(app_id))
end
info(app_id, backup_id) click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 20
def info(app_id, backup_id)
  @client.perform_get_request("/client/v11/apps/#{app_id}/transfers/#{backup_id}")
end
list(app_id) click to toggle source

backups: from_type == 'pg_dump' && to_type == 'gof3r' restores: from_type != 'pg_dump' && to_type == 'pg_restore' copies: from_type == 'pg_dump' && to_type == 'pg_restore'

# File lib/heroku/api/postgres/backups.rb, line 16
def list(app_id)
  @client.perform_get_request("/client/v11/apps/#{app_id}/transfers")
end
restore(app_id, database_id, backup_url) click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 56
def restore(app_id, database_id, backup_url)
  @client.perform_post_request("/client/v11/databases/#{database_id}/restores",
                               { backup_url: backup_url }, host: db_host(app_id))
end
schedule(app_id, database_id) click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 29
def schedule(app_id, database_id)
  @client.perform_post_request("/client/v11/databases/#{database_id}/transfer-schedules",
                               { hour: 0o0,
                                 timezone: 'UTC',
                                 schedule_name: 'DATABASE_URL' }, host: db_host(app_id))
end
schedules(app_id, database_id) click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 24
def schedules(app_id, database_id)
  @client.perform_get_request("/client/v11/databases/#{database_id}/transfer-schedules",
                              host: db_host(app_id))
end
url(app_id, backup_num) click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 40
def url(app_id, backup_num)
  @client.perform_post_request("/client/v11/apps/#{app_id}/transfers/#{backup_num}/actions/public-url")
end
wait(app_id, backup_id, options = { wait_interval: 3 }) { |backup| ... } click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 44
def wait(app_id, backup_id, options = { wait_interval: 3 })
  backup = nil
  loop do
    backup = info(app_id, backup_id)
    yield(backup) if block_given?
    break if backup[:finished_at]

    sleep(options[:wait_interval])
  end
  backup
end

Private Instance Methods

databases() click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 63
def databases
  @databases ||= Databases.new(@client)
end
db_host(app_id) click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 67
def db_host(app_id)
  database = heroku_client.addon.list_by_app(app_id).find do |addon|
    addon['addon_service']['name'] == 'heroku-postgresql'
  end
  databases.host_for(database)
end
heroku_client() click to toggle source
# File lib/heroku/api/postgres/backups.rb, line 74
def heroku_client
  @heroku_client ||= PlatformAPI.connect_oauth(@client.oauth_client_key)
end