Class: SwarmClusterCliOpe::SyncConfigs::Mysql
Defined Under Namespace
Classes: EnvConfigs
Instance Attribute Summary
Attributes inherited from Base
#configs, #service
Instance Method Summary
collapse
#local, #remote
Methods inherited from Base
#initialize
#logger
Instance Method Details
#pull ⇒ TrueClass, FalseClass
6
7
8
9
10
11
12
13
14
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
41
42
43
44
45
46
|
# File 'lib/swarm_cluster_cli_ope/sync_configs/mysql.rb', line 6
def pull
resume('pull')
if yes?("Confermare il comando?[y,yes]")
tmp_file = "/tmp/#{Time.now.to_i}.sql.gz"
remote_authentication = "-u #{remote.username} --password=#{remote.password}"
dump_command = "mysqldump #{remote_authentication}"
remote.excluded_tables_data.each do |t|
dump_command << " --ignore-table=#{remote.database_name}.#{t}"
end
dump_command << " #{remote.database_name}"
dump_command << " > /tmp/export.sql"
remote.excluded_tables_data.each do |t|
dump_command << " &&"
dump_command << " mysqldump #{remote_authentication}"
dump_command << " --no-data #{remote.database_name} #{t} >> /tmp/export.sql"
end
container.exec("bash -c '#{dump_command} && cat /tmp/export.sql | gzip -c -f' > #{tmp_file}")
local_container.copy_in(tmp_file, tmp_file)
local_authentication = "-u #{local.username} --password=#{local.password}"
command = []
command << "bash -c '"
command << "mysql #{local_authentication} -e \"DROP DATABASE IF EXISTS #{local.database_name};CREATE DATABASE #{local.database_name}\""
command << "&&"
command << "zcat #{tmp_file}"
command << "|"
command << "mysql #{local_authentication} #{local.database_name}"
command << "'"
local_container.exec(command.join " ")
end
true
end
|
#push ⇒ TrueClass, FalseClass
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/swarm_cluster_cli_ope/sync_configs/mysql.rb', line 49
def push
resume('PUSH')
if yes?("ATTENZIONE !!!!!!PUSH!!!!! - Confermare il comando?[y,yes]")
tmp_file = "/tmp/#{Time.now.to_i}.sql.gz"
local_container.exec("bash -c 'mysqldump -u #{local.username} --password=#{local.password} #{local.database_name} | gzip -c -f' > #{tmp_file}")
container.copy_in(tmp_file, tmp_file)
container.exec("bash -c 'zcat #{tmp_file} | mysql -u #{remote.username} --password=#{remote.password} #{remote.database_name}'")
end
true
end
|
#resume(direction) ⇒ Object
60
61
62
63
64
|
# File 'lib/swarm_cluster_cli_ope/sync_configs/mysql.rb', line 60
def resume(direction)
super
puts "excluded_tables: #{remote.excluded_tables_data.join(",")}"
end
|