Class: DatabasusRuby::Backups

Inherits:
Object
  • Object
show all
Includes:
Endpoint
Defined in:
lib/databasus_ruby/objects/backups.rb,
sig/databasus_ruby.rbs

Overview

Logical backups.

backups = client.backups.list(database_id: id, status: %w[COMPLETED FAILED])
backups.total
backups.first.fileName

Downloads are a two-step flow: mint a short-lived token, then stream the file with it. #download does both.

Constant Summary collapse

STATUSES =

Returns:

  • (Array[String])
%w[IN_PROGRESS COMPLETED FAILED CANCELED].freeze
ENCRYPTIONS =

Returns:

  • (Array[String])
%w[NONE ENCRYPTED].freeze
VERIFICATION_STATUSES =

Returns:

  • (Array[String])
%w[NOT_VERIFIED VERIFIED_SUCCESSFUL VERIFICATION_FAILED].freeze

Instance Attribute Summary

Attributes included from Endpoint

#client

Instance Method Summary collapse

Methods included from Endpoint

#acknowledged, #build, #collection, #compact, #escape, #http_delete, #http_get, #http_post, #http_put, #initialize, #inspect, #object, #single_value, #with_default_workspace

Methods inherited from Object

#==, #[], #hash, #initialize, #inspect, #key?, #keys, #method_missing, #respond_to_missing?, #to_h

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DatabasusRuby::Object

Instance Method Details

#cancel(id) ⇒ Boolean

POST /backups/id/cancel

Parameters:

  • id (String)

Returns:

  • (Boolean)


45
46
47
# File 'lib/databasus_ruby/objects/backups.rb', line 45

def cancel(id)
  acknowledged(http_post("backups/#{escape(id)}/cancel"))
end

#create(database_id:) ⇒ Object Also known as: trigger

POST /backups — queues a backup run for the database.

Parameters:

  • database_id: (String)

Returns:



34
35
36
# File 'lib/databasus_ruby/objects/backups.rb', line 34

def create(database_id:)
  object(http_post("backups", { database_id: database_id }))
end

#delete(id) ⇒ Boolean

DELETE /backups/id

Parameters:

  • id (String)

Returns:

  • (Boolean)


40
41
42
# File 'lib/databasus_ruby/objects/backups.rb', line 40

def delete(id)
  acknowledged(http_delete("backups/#{escape(id)}"))
end

#download(id) ⇒ [String, String]

Mints a token and fetches the file in one call. Returns [filename, contents].

Parameters:

  • id (String)

Returns:

  • ([String, String])


62
63
64
65
# File 'lib/databasus_ruby/objects/backups.rb', line 62

def download(id)
  grant = download_token(id)
  [grant.filename, file(id, token: grant.token)]
end

#download_token(id) ⇒ Object

POST /backups/id/download-token -> { token, filename, backupId }

Parameters:

  • id (String)

Returns:



50
51
52
# File 'lib/databasus_ruby/objects/backups.rb', line 50

def download_token(id)
  object(http_post("backups/#{escape(id)}/download-token"))
end

#file(id, token:) ⇒ String

GET /backups/id/file — returns the raw body; pass a token from #download_token.

Parameters:

  • id (String)
  • token: (String)

Returns:

  • (String)


56
57
58
# File 'lib/databasus_ruby/objects/backups.rb', line 56

def file(id, token:)
  http_get("backups/#{escape(id)}/file", { token: token }).body
end

#list(database_id:, limit: nil, offset: nil, status: nil, before_date: nil, pg_wal_backup_type: nil) ⇒ Object Also known as: all

GET /backups — status accepts a single value or an array.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/databasus_ruby/objects/backups.rb', line 20

def list(database_id:, limit: nil, offset: nil, status: nil, before_date: nil, pg_wal_backup_type: nil)
  response = http_get("backups", {
                        database_id: database_id,
                        limit: limit,
                        offset: offset,
                        status: status,
                        beforeDate: before_date,
                        pgWalBackupType: pg_wal_backup_type
                      })
  collection(response, key: "backups")
end