Class: KamalBackup::Databases::Base

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

Direct Known Subclasses

Mysql, Postgres, Sqlite

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, redactor:) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/kamal_backup/databases/base.rb', line 9

def initialize(config, redactor:)
  @config = config
  @redactor = redactor
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/kamal_backup/databases/base.rb', line 7

def config
  @config
end

#redactorObject (readonly)

Returns the value of attribute redactor.



7
8
9
# File 'lib/kamal_backup/databases/base.rb', line 7

def redactor
  @redactor
end

Instance Method Details

#adapter_nameObject

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/kamal_backup/databases/base.rb', line 36

def adapter_name
  raise NotImplementedError
end

#backup(restic, timestamp) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/kamal_backup/databases/base.rb', line 14

def backup(restic, timestamp)
  restic.backup_command_output(
    dump_command,
    filename: database_filename(timestamp),
    tags: backup_tags(timestamp)
  )
end

#backup_tags(timestamp) ⇒ Object



32
33
34
# File 'lib/kamal_backup/databases/base.rb', line 32

def backup_tags(timestamp)
  ["type:database", "adapter:#{adapter_name}", "run:#{timestamp}"]
end

#database_filename(timestamp) ⇒ Object



27
28
29
30
# File 'lib/kamal_backup/databases/base.rb', line 27

def database_filename(timestamp)
  app = config.app_name.gsub(/[^A-Za-z0-9_.-]+/, "-")
  "databases-#{app}-#{adapter_name}-#{timestamp}.#{dump_extension}"
end

#dump_commandObject

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/kamal_backup/databases/base.rb', line 44

def dump_command
  raise NotImplementedError
end

#dump_extensionObject

Raises:

  • (NotImplementedError)


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

def dump_extension
  raise NotImplementedError
end

#restore(restic, snapshot, filename) ⇒ Object



22
23
24
25
# File 'lib/kamal_backup/databases/base.rb', line 22

def restore(restic, snapshot, filename)
  validate_restore_target!
  restic.dump_file_to_command(snapshot, filename, restore_command)
end

#restore_commandObject

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/kamal_backup/databases/base.rb', line 48

def restore_command
  raise NotImplementedError
end

#restore_target_identifierObject

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/kamal_backup/databases/base.rb', line 56

def restore_target_identifier
  raise NotImplementedError
end

#validate_restore_target!Object



52
53
54
# File 'lib/kamal_backup/databases/base.rb', line 52

def validate_restore_target!
  config.validate_database_restore_target!(restore_target_identifier)
end