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



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

def adapter_name
  'sqlite'
end

#backup(restic) ⇒ Object



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

def backup(restic)
  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,
      tags: backup_tags
    )
  end
end

#current_target_identifierObject



47
48
49
# File 'lib/kamal_backup/databases/sqlite.rb', line 47

def current_target_identifier
  sqlite_source
end

#dump_commandObject

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/kamal_backup/databases/sqlite.rb', line 43

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

#dump_extensionObject



14
15
16
# File 'lib/kamal_backup/databases/sqlite.rb', line 14

def dump_extension
  'sqlite3'
end

#restore_to_current(restic, snapshot, filename) ⇒ Object



34
35
36
# File 'lib/kamal_backup/databases/sqlite.rb', line 34

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



38
39
40
41
# File 'lib/kamal_backup/databases/sqlite.rb', line 38

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



51
52
53
# File 'lib/kamal_backup/databases/sqlite.rb', line 51

def scratch_target_identifier(target)
  target
end