Class: Deploio::PostgresBackupService

Inherits:
Object
  • Object
show all
Defined in:
lib/deploio/postgres_backup_service.rb

Overview

Backups for the dedicated tier (kind: Postgres), where we own the whole database server and reach it over SSH The naming is confusing, but this is how Nine names them and how the resources appear, so prefer to stay consistent with that

Constant Summary collapse

DEFAULT_EXTENSION =
".zst"

Instance Method Summary collapse

Constructor Details

#initialize(data:, name: nil, dry_run: false) ⇒ PostgresBackupService

Returns a new instance of PostgresBackupService.

Parameters:

  • name (String) (defaults to: nil)

    the name the user typed, used for hints in messages



12
13
14
15
16
# File 'lib/deploio/postgres_backup_service.rb', line 12

def initialize(data:, name: nil, dry_run: false)
  @data = data || {}
  @name = name
  @dry_run = dry_run
end

Instance Method Details

#backupsObject



20
21
22
23
24
# File 'lib/deploio/postgres_backup_service.rb', line 20

def backups
  raise Deploio::UnsupportedBackupOperationError,
    "Listing backups is not yet supported for dedicated PostgreSQL instances; Feel free to implement it!\n" \
    "Use 'deploio pg backups download #{@name}' to fetch it."
end

#captureObject



26
27
28
29
30
# File 'lib/deploio/postgres_backup_service.rb', line 26

def capture
  cmd = ["ssh", "dbadmin@#{fqdn}", "sudo nine-postgresql-backup"]
  Output.command(cmd.join(" "))
  system(*cmd) unless @dry_run
end

#default_destinationObject



18
# File 'lib/deploio/postgres_backup_service.rb', line 18

def default_destination = "./#{@name}-latest-backup#{DEFAULT_EXTENSION}"

#download(destination:, db_name: nil) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/deploio/postgres_backup_service.rb', line 32

def download(destination:, db_name: nil)
  name = resolve_db_name(db_name)

  cmd = ["rsync", "-av", "dbadmin@#{fqdn}:~/backup/postgresql/latest/customer/#{name}/#{name}.zst", destination]
  Output.command(cmd.join(" "))
  system(*cmd) unless @dry_run

  nil
end