Class: MysqlSlaver::DbCopier
- Inherits:
-
Object
- Object
- MysqlSlaver::DbCopier
- Includes:
- MysqlCommand
- Defined in:
- lib/mysql_slaver/db_copier.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
-
#executor ⇒ Object
Returns the value of attribute executor.
-
#master_host ⇒ Object
Returns the value of attribute master_host.
-
#mysql_root_password ⇒ Object
Returns the value of attribute mysql_root_password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#socket_file ⇒ Object
Returns the value of attribute socket_file.
-
#tables ⇒ Object
Returns the value of attribute tables.
Instance Method Summary collapse
- #copy! ⇒ Object
-
#initialize(params) ⇒ DbCopier
constructor
A new instance of DbCopier.
Methods included from MysqlCommand
#mysql_command, #mysql_credentials
Constructor Details
#initialize(params) ⇒ DbCopier
Returns a new instance of DbCopier.
7 8 9 10 11 12 13 14 15 |
# File 'lib/mysql_slaver/db_copier.rb', line 7 def initialize(params) @master_host = params.fetch(:master_host) @mysql_root_password = params.fetch(:mysql_root_password, '') @database = params.fetch(:database) @port = params.fetch(:port, nil) @socket_file = params.fetch(:socket_file, nil) @executor = params.fetch(:executor) { Executor.new(ssh_port: params[:ssh_port]) } @tables = params.fetch(:tables, nil) end |
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
5 6 7 |
# File 'lib/mysql_slaver/db_copier.rb', line 5 def database @database end |
#executor ⇒ Object
Returns the value of attribute executor.
5 6 7 |
# File 'lib/mysql_slaver/db_copier.rb', line 5 def executor @executor end |
#master_host ⇒ Object
Returns the value of attribute master_host.
5 6 7 |
# File 'lib/mysql_slaver/db_copier.rb', line 5 def master_host @master_host end |
#mysql_root_password ⇒ Object
Returns the value of attribute mysql_root_password.
5 6 7 |
# File 'lib/mysql_slaver/db_copier.rb', line 5 def mysql_root_password @mysql_root_password end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/mysql_slaver/db_copier.rb', line 5 def port @port end |
#socket_file ⇒ Object
Returns the value of attribute socket_file.
5 6 7 |
# File 'lib/mysql_slaver/db_copier.rb', line 5 def socket_file @socket_file end |
#tables ⇒ Object
Returns the value of attribute tables.
5 6 7 |
# File 'lib/mysql_slaver/db_copier.rb', line 5 def tables @tables end |
Instance Method Details
#copy! ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/mysql_slaver/db_copier.rb', line 17 def copy! executor.execute mysql_command("stop slave", mysql_params) cmd = mysqldump dump_cmd = executor.ssh_command(cmd, master_host) load_cmd = ['mysql', mysql_credentials('root', mysql_params), database].join(' ') command = [dump_cmd, load_cmd].join(' | ') executor.execute command end |