Class: Heroku::Api::Postgres::Backups

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku/api/postgres/backups.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Backups

Returns a new instance of Backups.



11
12
13
# File 'lib/heroku/api/postgres/backups.rb', line 11

def initialize(client)
  @client = client
end

Instance Method Details

#capture(database_id, options = {}) ⇒ Object



37
38
39
# File 'lib/heroku/api/postgres/backups.rb', line 37

def capture(database_id, options = {})
  @client.perform_post_request("/client/v11/databases/#{database_id}/backups", options)
end

#info(app_id, backup_id) ⇒ Object



22
23
24
# File 'lib/heroku/api/postgres/backups.rb', line 22

def info(app_id, backup_id)
  @client.perform_get_request("/client/v11/apps/#{app_id}/transfers/#{backup_id}")
end

#list(app_id) ⇒ Object

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’



18
19
20
# File 'lib/heroku/api/postgres/backups.rb', line 18

def list(app_id)
  @client.perform_get_request("/client/v11/apps/#{app_id}/transfers")
end

#restore(database_id, backup_url) ⇒ Object



64
65
66
67
# File 'lib/heroku/api/postgres/backups.rb', line 64

def restore(database_id, backup_url)
  @client.perform_post_request("/client/v11/databases/#{database_id}/restores",
                               { backup_url: backup_url })
end

#schedule(database_id, hour: 0, timezone: 'UTC') ⇒ Object



30
31
32
33
34
35
# File 'lib/heroku/api/postgres/backups.rb', line 30

def schedule(database_id, hour: 0, timezone: 'UTC')
  @client.perform_post_request("/client/v11/databases/#{database_id}/transfer-schedules",
                               { hour: hour,
                                 timezone: timezone,
                                 schedule_name: 'DATABASE_URL' })
end

#schedules(database_id) ⇒ Object



26
27
28
# File 'lib/heroku/api/postgres/backups.rb', line 26

def schedules(database_id)
  @client.perform_get_request("/client/v11/databases/#{database_id}/transfer-schedules")
end

#url(app_id, backup_num = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/heroku/api/postgres/backups.rb', line 41

def url(app_id, backup_num = nil)
  unless backup_num
    transfers = list(app_id)
    last_transfer =
      transfers.select { |t| t[:succeeded] && t[:to_type] == 'gof3r' }
               .max_by { |t| t[:created_at] }
    backup_num = last_transfer[:num]
  end
  @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 }) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/heroku/api/postgres/backups.rb', line 52

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