Class: Backup::Database::MySQL
- Defined in:
- lib/backup/database/mysql.rb
Constant Summary
Constants included from CLI::Helpers
Instance Attribute Summary collapse
-
#additional_options ⇒ Object
Additional “mysqldump” options.
-
#host ⇒ Object
Connectivity options.
-
#mysqldump_utility ⇒ Object
Path to mysqldump utility (optional).
-
#name ⇒ Object
Name of the database that needs to get dumped To dump all databases, set this to ‘:all` or leave blank.
-
#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
-
#initialize(model, &block) ⇒ MySQL
constructor
Creates a new instance of the MySQL adapter object.
-
#perform! ⇒ Object
Performs the mysqldump command and outputs the data to the specified path based on the ‘trigger’.
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_options ⇒ Object
Additional “mysqldump” options
30 31 32 |
# File 'lib/backup/database/mysql.rb', line 30 def @additional_options end |
#host ⇒ Object
Connectivity options
18 19 20 |
# File 'lib/backup/database/mysql.rb', line 18 def host @host end |
#mysqldump_utility ⇒ Object
Path to mysqldump utility (optional)
34 35 36 |
# File 'lib/backup/database/mysql.rb', line 34 def mysqldump_utility @mysqldump_utility end |
#name ⇒ Object
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_tables ⇒ Object
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 |
#password ⇒ Object
Credentials for the specified database
14 15 16 |
# File 'lib/backup/database/mysql.rb', line 14 def password @password end |
#port ⇒ Object
Connectivity options
18 19 20 |
# File 'lib/backup/database/mysql.rb', line 18 def port @port end |
#skip_tables ⇒ Object
Tables to skip while dumping the database
22 23 24 |
# File 'lib/backup/database/mysql.rb', line 22 def skip_tables @skip_tables end |
#socket ⇒ Object
Connectivity options
18 19 20 |
# File 'lib/backup/database/mysql.rb', line 18 def socket @socket end |
#username ⇒ Object
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. "#{ database_name } Complete!" else raise Errors::Database::PipelineError, "#{ database_name } Dump Failed!\n" + pipeline. end end |