Class: Backup::Database::MySQL

Inherits:
Base
  • Object
show all
Defined in:
lib/backup/database/mysql.rb

Constant Summary

Constants included from CLI::Helpers

CLI::Helpers::UTILITY

Instance Attribute Summary collapse

Attributes inherited from Base

#utility_path

Instance Method Summary collapse

Methods included from Configuration::Helpers

#clear_defaults!, #load_defaults!

Methods included from CLI::Helpers

#command_name, #raise_if_command_failed!, #run, #utility

Constructor Details

#initialize(model, &block) ⇒ MySQL

Creates a new instance of the MySQL adapter object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/backup/database/mysql.rb', line 38

def initialize(model, &block)
  super(model)

  @skip_tables        ||= Array.new
  @only_tables        ||= Array.new
  @additional_options ||= Array.new

  instance_eval(&block) if block_given?

  @name ||= :all

  if @utility_path
    Logger.warn "[DEPRECATED] " +
      "Database::MySQL#utility_path has been deprecated.\n" +
      "  Use Database::MySQL#mysqldump_utility instead."
    @mysqldump_utility ||= @utility_path
  end
  @mysqldump_utility ||= utility(:mysqldump)
end

Instance Attribute Details

#additional_optionsObject

Additional “mysqldump” options



30
31
32
# File 'lib/backup/database/mysql.rb', line 30

def additional_options
  @additional_options
end

#hostObject

Connectivity options



18
19
20
# File 'lib/backup/database/mysql.rb', line 18

def host
  @host
end

#mysqldump_utilityObject

Path to mysqldump utility (optional)



34
35
36
# File 'lib/backup/database/mysql.rb', line 34

def mysqldump_utility
  @mysqldump_utility
end

#nameObject

Name of the database that needs to get dumped To dump all databases, set this to ‘:all` or leave blank.



10
11
12
# File 'lib/backup/database/mysql.rb', line 10

def name
  @name
end

#only_tablesObject

Tables to dump, tables that aren’t specified won’t get dumped



26
27
28
# File 'lib/backup/database/mysql.rb', line 26

def only_tables
  @only_tables
end

#passwordObject

Credentials for the specified database



14
15
16
# File 'lib/backup/database/mysql.rb', line 14

def password
  @password
end

#portObject

Connectivity options



18
19
20
# File 'lib/backup/database/mysql.rb', line 18

def port
  @port
end

#skip_tablesObject

Tables to skip while dumping the database



22
23
24
# File 'lib/backup/database/mysql.rb', line 22

def skip_tables
  @skip_tables
end

#socketObject

Connectivity options



18
19
20
# File 'lib/backup/database/mysql.rb', line 18

def socket
  @socket
end

#usernameObject

Credentials for the specified database



14
15
16
# File 'lib/backup/database/mysql.rb', line 14

def username
  @username
end

Instance Method Details

#perform!Object

Performs the mysqldump command and outputs the data to the specified path based on the ‘trigger’



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/backup/database/mysql.rb', line 61

def perform!
  super

  pipeline = Pipeline.new
  dump_ext = 'sql'

  pipeline << mysqldump
  if @model.compressor
    @model.compressor.compress_with do |command, ext|
      pipeline << command
      dump_ext << ext
    end
  end
  pipeline << "cat > '#{ File.join(@dump_path, dump_filename) }.#{ dump_ext }'"

  pipeline.run
  if pipeline.success?
    Logger.message "#{ database_name } Complete!"
  else
    raise Errors::Database::PipelineError,
        "#{ database_name } Dump Failed!\n" +
        pipeline.error_messages
  end
end