Class: KamalBackup::Databases::Mysql

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

Instance Attribute Summary

Attributes inherited from Base

#config, #redactor

Instance Method Summary collapse

Methods inherited from Base

#backup, #backup_tags, build, #database_filename, #initialize

Constructor Details

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

Instance Method Details

#adapter_nameObject



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

def adapter_name
  'mysql'
end

#current_restore_commandObject



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

def current_restore_command
  connection = current_connection
  argv = [client_binary] + connection_args(connection)
  argv << connection.fetch(:database)
  CommandSpec.new(argv: argv, env: password_env(connection))
end

#current_target_identifierObject



58
59
60
61
# File 'lib/kamal_backup/databases/mysql.rb', line 58

def current_target_identifier
  connection = current_connection
  [connection[:host], connection[:database]].compact.join('/')
end

#dump_commandObject



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

def dump_command
  connection = current_connection
  argv = [
    dump_binary,
    '--single-transaction',
    '--quick',
    '--skip-comments',
    '--no-tablespaces',
    '--routines',
    '--triggers',
    '--events'
  ] + connection_args(connection)
  argv << connection.fetch(:database)
  CommandSpec.new(argv: argv, env: password_env(connection))
end

#dump_extensionObject



13
14
15
# File 'lib/kamal_backup/databases/mysql.rb', line 13

def dump_extension
  'sql'
end

#restore_to_current(restic, snapshot, filename) ⇒ Object



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

def restore_to_current(restic, snapshot, filename)
  reset_database(current_connection)
  super
end

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



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

def restore_to_scratch(restic, snapshot, filename, target:)
  validate_scratch_restore_target(target)
  reset_database(current_connection.merge(database: target))
  restic.pipe_dump_to_command(snapshot, filename, scratch_restore_command(target))
end

#scratch_restore_command(target) ⇒ Object



51
52
53
54
55
56
# File 'lib/kamal_backup/databases/mysql.rb', line 51

def scratch_restore_command(target)
  connection = current_connection.merge(database: target)
  argv = [client_binary] + connection_args(connection)
  argv << target
  CommandSpec.new(argv: argv, env: password_env(connection))
end

#scratch_target_identifier(target) ⇒ Object



63
64
65
# File 'lib/kamal_backup/databases/mysql.rb', line 63

def scratch_target_identifier(target)
  [current_connection[:host], target].compact.join('/')
end