Class: MysqlSlaver::DbCopier

Inherits:
Object
  • Object
show all
Includes:
MysqlCommand
Defined in:
lib/mysql_slaver/db_copier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#databaseObject

Returns the value of attribute database.



5
6
7
# File 'lib/mysql_slaver/db_copier.rb', line 5

def database
  @database
end

#executorObject

Returns the value of attribute executor.



5
6
7
# File 'lib/mysql_slaver/db_copier.rb', line 5

def executor
  @executor
end

#master_hostObject

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_passwordObject

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

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/mysql_slaver/db_copier.rb', line 5

def port
  @port
end

#socket_fileObject

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

#tablesObject

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