Class: Backup::Database::MySQL
- Defined in:
- lib/backup/database/mysql.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#additional_options ⇒ Object
Additional “mysqldump” or “innobackupex (backup creation)” options.
-
#backup_engine ⇒ Object
Default is :mysqldump (which is built in MySQL and generates a textual SQL file), but can be changed to :innobackupex, which has more feasible restore times for large databases.
-
#host ⇒ Object
Connectivity options.
-
#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.
-
#password ⇒ Object
Credentials for the specified database.
-
#port ⇒ Object
Connectivity options.
-
#prepare_backup ⇒ Object
If true (which is the default behaviour), the backup will be prepared after it has been successfuly created.
-
#prepare_options ⇒ Object
Additional innobackupex log preparation phase (“apply-logs”) options.
-
#skip_tables ⇒ Object
Tables to skip while dumping the database.
-
#socket ⇒ Object
Connectivity options.
-
#sudo_user ⇒ Object
If set the backup engine command block is executed as the given user.
-
#username ⇒ Object
Credentials for the specified database.
-
#verbose ⇒ Object
If set, do not suppress innobackupdb output (useful for debugging).
Attributes inherited from Base
#database_id, #dump_path, #model
Instance Method Summary collapse
-
#initialize(model, database_id = nil, &block) ⇒ MySQL
constructor
A new instance of MySQL.
-
#perform! ⇒ Object
Performs the mysqldump or innobackupex command and outputs the dump file in the
dump_pathusingdump_filename.
Methods included from Config::Helpers
Constructor Details
#initialize(model, database_id = nil, &block) ⇒ MySQL
Returns a new instance of MySQL.
61 62 63 64 65 66 67 68 |
# File 'lib/backup/database/mysql.rb', line 61 def initialize(model, database_id = nil, &block) super instance_eval(&block) if block_given? @name ||= :all @backup_engine ||= :mysqldump @prepare_backup = true if @prepare_backup.nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Backup::Config::Helpers
Instance Attribute Details
#additional_options ⇒ Object
Additional “mysqldump” or “innobackupex (backup creation)” options
34 35 36 |
# File 'lib/backup/database/mysql.rb', line 34 def end |
#backup_engine ⇒ Object
Default is :mysqldump (which is built in MySQL and generates a textual SQL file), but can be changed to :innobackupex, which has more feasible restore times for large databases. See: www.percona.com/doc/percona-xtrabackup/
45 46 47 |
# File 'lib/backup/database/mysql.rb', line 45 def backup_engine @backup_engine 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 To dump all databases, set this to ‘:all` or leave blank.
9 10 11 |
# File 'lib/backup/database/mysql.rb', line 9 def name @name end |
#only_tables ⇒ Object
Tables to dump. This in only valid if ‘name` is specified. If none are given, the entire database will be dumped.
30 31 32 |
# File 'lib/backup/database/mysql.rb', line 30 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 |
#prepare_backup ⇒ Object
If true (which is the default behaviour), the backup will be prepared after it has been successfuly created. This option is only valid if :backup_engine is set to :innobackupex.
51 52 53 |
# File 'lib/backup/database/mysql.rb', line 51 def prepare_backup @prepare_backup end |
#prepare_options ⇒ Object
Additional innobackupex log preparation phase (“apply-logs”) options
38 39 40 |
# File 'lib/backup/database/mysql.rb', line 38 def end |
#skip_tables ⇒ Object
Tables to skip while dumping the database
If ‘name` is set to :all (or not specified), these must include a database name. e.g. ’name.table’. If ‘name` is given, these may simply be table names.
25 26 27 |
# File 'lib/backup/database/mysql.rb', line 25 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 |
#sudo_user ⇒ Object
If set the backup engine command block is executed as the given user
55 56 57 |
# File 'lib/backup/database/mysql.rb', line 55 def sudo_user @sudo_user end |
#username ⇒ Object
Credentials for the specified database
13 14 15 |
# File 'lib/backup/database/mysql.rb', line 13 def username @username end |
#verbose ⇒ Object
If set, do not suppress innobackupdb output (useful for debugging)
59 60 61 |
# File 'lib/backup/database/mysql.rb', line 59 def verbose @verbose end |
Instance Method Details
#perform! ⇒ Object
Performs the mysqldump or innobackupex command and outputs the dump file in the dump_path using dump_filename.
<trigger>/databases/MySQL[-<database_id>].[sql|tar][.gz]
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/backup/database/mysql.rb', line 75 def perform! super pipeline = Pipeline.new dump_ext = sql_backup? ? "sql" : "tar" pipeline << sudo_option(sql_backup? ? mysqldump : innobackupex) if model.compressor model.compressor.compress_with do |command, ext| pipeline << command dump_ext << ext end end pipeline << "#{utility(:cat)} > " \ "'#{File.join(dump_path, dump_filename)}.#{dump_ext}'" pipeline.run if pipeline.success? log!(:finished) else raise Error, "Dump Failed!\n#{pipeline.error_messages}" end end |