Class: Backup::Database::MySQL
- Defined in:
- lib/backup/database/mysql.rb
Instance Attribute Summary collapse
-
#additional_options ⇒ Object
Additional “mysqldump” options.
-
#host ⇒ Object
Connectivity options.
-
#name ⇒ Object
Name of the database that needs to get dumped.
-
#only_tables ⇒ Object
Tables to dump, tables that aren’t specified won’t get dumped.
-
#password ⇒ Object
Credentials for the specified database.
-
#port ⇒ Object
Connectivity options.
-
#skip_tables ⇒ Object
Tables to skip while dumping the database.
-
#socket ⇒ Object
Connectivity options.
-
#username ⇒ Object
Credentials for the specified database.
Attributes inherited from Base
Instance Method Summary collapse
-
#connectivity_options ⇒ Object
Builds the MySQL connectivity options syntax to connect the user to perform the database dumping process.
-
#credential_options ⇒ Object
Builds the credentials MySQL syntax to authenticate the user to perform the database dumping process.
-
#initialize(&block) ⇒ MySQL
constructor
Creates a new instance of the MySQL adapter object.
-
#mysqldump ⇒ Object
Builds the full mysqldump string based on all attributes.
-
#options ⇒ Object
Builds a MySQL compatible string for the additional options specified by the user.
-
#perform! ⇒ Object
Performs the mysqldump command and outputs the data to the specified path based on the ‘trigger’.
-
#tables_to_dump ⇒ Object
Builds the MySQL syntax for specifying which tables to dump during the dumping of the database.
-
#tables_to_skip ⇒ Object
Builds the MySQL syntax for specifying which tables to skip during the dumping of the database.
Methods inherited from Base
Methods included from Configuration::Helpers
#clear_defaults!, #getter_methods, #load_defaults!, #setter_methods
Methods included from CLI
Constructor Details
#initialize(&block) ⇒ MySQL
Creates a new instance of the MySQL adapter object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/backup/database/mysql.rb', line 33 def initialize(&block) load_defaults! @skip_tables ||= Array.new @only_tables ||= Array.new @additional_options ||= Array.new instance_eval(&block) prepare! end |
Instance Attribute Details
#additional_options ⇒ Object
Additional “mysqldump” options
29 30 31 |
# File 'lib/backup/database/mysql.rb', line 29 def @additional_options end |
#host ⇒ Object
Connectivity options
17 18 19 |
# File 'lib/backup/database/mysql.rb', line 17 def host @host end |
#name ⇒ Object
Name of the database that needs to get dumped
9 10 11 |
# File 'lib/backup/database/mysql.rb', line 9 def name @name end |
#only_tables ⇒ Object
Tables to dump, tables that aren’t specified won’t get dumped
25 26 27 |
# File 'lib/backup/database/mysql.rb', line 25 def only_tables @only_tables end |
#password ⇒ Object
Credentials for the specified database
13 14 15 |
# File 'lib/backup/database/mysql.rb', line 13 def password @password end |
#port ⇒ Object
Connectivity options
17 18 19 |
# File 'lib/backup/database/mysql.rb', line 17 def port @port end |
#skip_tables ⇒ Object
Tables to skip while dumping the database
21 22 23 |
# File 'lib/backup/database/mysql.rb', line 21 def skip_tables @skip_tables end |
#socket ⇒ Object
Connectivity options
17 18 19 |
# File 'lib/backup/database/mysql.rb', line 17 def socket @socket end |
#username ⇒ Object
Credentials for the specified database
13 14 15 |
# File 'lib/backup/database/mysql.rb', line 13 def username @username end |
Instance Method Details
#connectivity_options ⇒ Object
Builds the MySQL connectivity options syntax to connect the user to perform the database dumping process
73 74 75 76 77 78 |
# File 'lib/backup/database/mysql.rb', line 73 def %w[host port socket].map do |option| next if send(option).nil? or (send(option).respond_to?(:empty?) and send(option).empty?) "--#{option}='#{send(option)}'" end.compact.join("\s") end |
#credential_options ⇒ Object
Builds the credentials MySQL syntax to authenticate the user to perform the database dumping process
63 64 65 66 67 68 |
# File 'lib/backup/database/mysql.rb', line 63 def %w[username password].map do |option| next if send(option).nil? or send(option).empty? "--#{option}='#{send(option)}'".gsub('--username', '--user') end.compact.join("\s") end |
#mysqldump ⇒ Object
Builds the full mysqldump string based on all attributes
89 90 91 92 |
# File 'lib/backup/database/mysql.rb', line 89 def mysqldump "#{ utility(:mysqldump) } #{ } #{ } " + "#{ } #{ name } #{ tables_to_dump } #{ tables_to_skip }" end |
#options ⇒ Object
Builds a MySQL compatible string for the additional options specified by the user
83 84 85 |
# File 'lib/backup/database/mysql.rb', line 83 def .join("\s") end |
#perform! ⇒ Object
Performs the mysqldump command and outputs the data to the specified path based on the ‘trigger’
97 98 99 100 |
# File 'lib/backup/database/mysql.rb', line 97 def perform! log! run("#{mysqldump} > '#{File.join(dump_path, name)}.sql'") end |
#tables_to_dump ⇒ Object
Builds the MySQL syntax for specifying which tables to dump during the dumping of the database
56 57 58 |
# File 'lib/backup/database/mysql.rb', line 56 def tables_to_dump only_tables.join("\s") end |
#tables_to_skip ⇒ Object
Builds the MySQL syntax for specifying which tables to skip during the dumping of the database
47 48 49 50 51 |
# File 'lib/backup/database/mysql.rb', line 47 def tables_to_skip skip_tables.map do |table| "--ignore-table='#{name}.#{table}'" end.join("\s") end |