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(app_id, database_id) ⇒ Object



38
39
40
41
42
# File 'lib/heroku/api/postgres/backups.rb', line 38

def capture(app_id, database_id)
  @client.perform_post_request("/client/v11/databases/#{database_id}/backups",
                               {},
                               host: db_host(app_id, database_id))
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(app_id, database_id, backup_url) ⇒ Object



67
68
69
70
# File 'lib/heroku/api/postgres/backups.rb', line 67

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, database_id))
end

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



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

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

#schedules(app_id, database_id) ⇒ Object



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

def schedules(app_id, database_id)
  @client.perform_get_request("/client/v11/databases/#{database_id}/transfer-schedules",
                              host: db_host(app_id, database_id))
end

#url(app_id, backup_num = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/heroku/api/postgres/backups.rb', line 44

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



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/heroku/api/postgres/backups.rb', line 55

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