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

Instance Method Summary collapse

Methods included from Configuration::Helpers

included

Constructor Details

#initialize(model, &block) ⇒ MySQL

Creates a new instance of the MySQL adapter object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/backup/database/mysql.rb', line 42

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
  @mysqldump_utility ||= utility(:mysqldump)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Backup::Configuration::Helpers

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’



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

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