Class: KamalBackup::Databases::Postgres

Inherits:
Base
  • Object
show all
Defined in:
lib/kamal_backup/databases/postgres.rb

Constant Summary collapse

SOURCE_ENV_KEYS =
%w[
  PGHOST
  PGPORT
  PGUSER
  PGPASSWORD
  PGDATABASE
  PGSSLMODE
  PGSSLROOTCERT
  PGSSLCERT
  PGSSLKEY
  PGCONNECT_TIMEOUT
  PGSERVICE
  PGPASSFILE
].freeze
RESTORE_ENV_MAP =
{
  "RESTORE_PGHOST" => "PGHOST",
  "RESTORE_PGPORT" => "PGPORT",
  "RESTORE_PGUSER" => "PGUSER",
  "RESTORE_PGPASSWORD" => "PGPASSWORD",
  "RESTORE_PGDATABASE" => "PGDATABASE",
  "RESTORE_PGSSLMODE" => "PGSSLMODE"
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#config, #redactor

Instance Method Summary collapse

Methods inherited from Base

#backup, #backup_tags, #database_filename, #initialize, #restore, #validate_restore_target!

Constructor Details

This class inherits a constructor from KamalBackup::Databases::Base

Instance Method Details

#adapter_nameObject



31
32
33
# File 'lib/kamal_backup/databases/postgres.rb', line 31

def adapter_name
  "postgres"
end

#dump_commandObject



39
40
41
42
# File 'lib/kamal_backup/databases/postgres.rb', line 39

def dump_command
  argv = %w[pg_dump --format=custom --no-owner --no-privileges]
  CommandSpec.new(argv: argv, env: backup_env)
end

#dump_extensionObject



35
36
37
# File 'lib/kamal_backup/databases/postgres.rb', line 35

def dump_extension
  "pgdump"
end

#restore_commandObject



44
45
46
47
48
49
50
51
# File 'lib/kamal_backup/databases/postgres.rb', line 44

def restore_command
  connection = restore_connection
  database = connection.fetch("PGDATABASE")

  argv = %w[pg_restore --clean --if-exists --no-owner --no-privileges --dbname]
  argv << database
  CommandSpec.new(argv: argv, env: connection)
end

#restore_target_identifierObject



53
54
55
# File 'lib/kamal_backup/databases/postgres.rb', line 53

def restore_target_identifier
  value("RESTORE_DATABASE_URL") || value("RESTORE_PGDATABASE")
end