Class: KamalBackup::Databases::Sqlite

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

Instance Attribute Summary

Attributes inherited from Base

#config, #redactor

Instance Method Summary collapse

Methods inherited from Base

#backup_tags, build, #current_restore_command, #database_filename, #initialize, #scratch_restore_command

Constructor Details

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

Instance Method Details

#adapter_nameObject



8
9
10
# File 'lib/kamal_backup/databases/sqlite.rb', line 8

def adapter_name
  "sqlite"
end

#backup(restic, timestamp) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kamal_backup/databases/sqlite.rb', line 16

def backup(restic, timestamp)
  source = sqlite_source
  Tempfile.create(["kamal-backup-", ".sqlite3"]) do |tempfile|
    tempfile.close
    Command.capture(
      CommandSpec.new(argv: ["sqlite3", source, ".backup #{sqlite_literal(tempfile.path)}"]),
      redactor: redactor
    )
    restic.backup_file(
      tempfile.path,
      filename: database_filename(timestamp),
      tags: backup_tags(timestamp)
    )
  end
end

#current_target_identifierObject



45
46
47
# File 'lib/kamal_backup/databases/sqlite.rb', line 45

def current_target_identifier
  sqlite_source
end

#dump_commandObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/kamal_backup/databases/sqlite.rb', line 41

def dump_command
  raise NotImplementedError, "SQLite backup uses .backup into a temporary file"
end

#dump_extensionObject



12
13
14
# File 'lib/kamal_backup/databases/sqlite.rb', line 12

def dump_extension
  "sqlite3"
end

#restore_to_current(restic, snapshot, filename) ⇒ Object



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

def restore_to_current(restic, snapshot, filename)
  restic.write_dump_to_path(snapshot, filename, sqlite_source)
end

#restore_to_scratch(restic, snapshot, filename, target:) ⇒ Object



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

def restore_to_scratch(restic, snapshot, filename, target:)
  validate_scratch_restore_target(target)
  restic.write_dump_to_path(snapshot, filename, target)
end

#scratch_target_identifier(target) ⇒ Object



49
50
51
# File 'lib/kamal_backup/databases/sqlite.rb', line 49

def scratch_target_identifier(target)
  target
end