Class: MysqlMirror
- Inherits:
-
Object
show all
- Defined in:
- lib/mysql_mirror.rb
Defined Under Namespace
Classes: MysqlMirrorException, Source, Target
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ MysqlMirror
Returns a new instance of MysqlMirror.
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/mysql_mirror.rb', line 15
def initialize(options = {})
unless ([:source, :target] - options.keys).blank?
raise MysqlMirrorException.new("You must specify both Source and Target connections")
end
self.tables = options.delete(:tables)
self.where = options.delete(:where)
overrides = options.delete(:override) || {}
source_override = overrides.delete(:source) || {}
target_override = overrides.delete(:target) || {}
@source_config = get_configuration(options.delete(:source))
@target_config = get_configuration(options.delete(:target))
@source_config.merge!(source_override)
@target_config.merge!(target_override)
if mirroring_same_host?
@commands = commands_for_local_mirror
else
@commands = commands_for_remote_mirror
end
end
|
Instance Attribute Details
#tables ⇒ Object
Returns the value of attribute tables.
13
14
15
|
# File 'lib/mysql_mirror.rb', line 13
def tables
@tables
end
|
#where ⇒ Object
Returns the value of attribute where.
13
14
15
|
# File 'lib/mysql_mirror.rb', line 13
def where
@where
end
|
Instance Method Details
#commands_for_local_mirror ⇒ Object
42
43
44
|
# File 'lib/mysql_mirror.rb', line 42
def commands_for_local_mirror
[:local_copy]
end
|
#commands_for_remote_mirror ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/mysql_mirror.rb', line 46
def commands_for_remote_mirror
[
:remote_mysqldump,
:remote_tmp_file_table_rename,
:remote_insert_command,
:remote_rename_tmp_tables,
:remote_remove_tmp_file
]
end
|
#execute! ⇒ Object
60
61
62
63
64
65
66
67
68
|
# File 'lib/mysql_mirror.rb', line 60
def execute!
@start_time = Time.now
@source = connect_to(:source)
@target = connect_to(:target)
@commands.each do |c|
self.send(c)
end
end
|
#mirroring_same_host? ⇒ Boolean
56
57
58
|
# File 'lib/mysql_mirror.rb', line 56
def mirroring_same_host?
@source_config[:host] == @target_config[:host]
end
|
#to_s ⇒ Object
70
71
72
|
# File 'lib/mysql_mirror.rb', line 70
def to_s
"Mirroring #{self.tables.join(', ')} from #{@source_config[:host]}.#{@source_config[:database]} to #{@target_config[:host]}.#{@target_config[:database]}"
end
|