myreplicator 1.1.20 → 1.1.21
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/myreplicator/log.rb +4 -3
- data/lib/exporter/mysql_exporter.rb +7 -10
- data/lib/exporter/sql_commands.rb +4 -4
- data/lib/loader/loader.rb +69 -38
- data/lib/myreplicator/version.rb +1 -1
- data/lib/transporter/transporter.rb +39 -2
- metadata +4 -4
@@ -148,10 +148,11 @@ module Myreplicator
|
|
148
148
|
log = Log.where(:export_id => options[:export_id],
|
149
149
|
:file => options[:file],
|
150
150
|
:job_type => options[:job_type]).last
|
151
|
-
Kernel.p "===== transport_complete? log ====="
|
152
|
-
Kernel.p log
|
151
|
+
#Kernel.p "===== transport_complete? log ====="
|
152
|
+
#Kernel.p log
|
153
153
|
if log.nil?
|
154
|
-
return false
|
154
|
+
#return false
|
155
|
+
return true
|
155
156
|
else
|
156
157
|
return true if log.state == "completed"
|
157
158
|
end
|
@@ -134,8 +134,8 @@ module Myreplicator
|
|
134
134
|
options[:incremental_val] = @export_obj.max_incremental_value
|
135
135
|
end
|
136
136
|
|
137
|
-
Kernel.p "===== incremental_export_into_outfile OPTIONS ====="
|
138
|
-
Kernel.p options
|
137
|
+
#Kernel.p "===== incremental_export_into_outfile OPTIONS ====="
|
138
|
+
#Kernel.p options
|
139
139
|
cmd = SqlCommands.mysql_export_outfile(options)
|
140
140
|
exporting_state_trans
|
141
141
|
puts "Exporting..."
|
@@ -152,8 +152,8 @@ module Myreplicator
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def self.compare_schemas vertica_schema, mysql_schema
|
155
|
-
Kernel.p vertica_schema
|
156
|
-
Kernel.p mysql_schema
|
155
|
+
#Kernel.p vertica_schema
|
156
|
+
#Kernel.p mysql_schema
|
157
157
|
if vertica_schema.size != mysql_schema.size
|
158
158
|
return true
|
159
159
|
else
|
@@ -196,8 +196,8 @@ module Myreplicator
|
|
196
196
|
end
|
197
197
|
|
198
198
|
def self.schema_changed? options
|
199
|
-
Kernel.p "===== schema_changed? ====="
|
200
|
-
puts options
|
199
|
+
#Kernel.p "===== schema_changed? ====="
|
200
|
+
#puts options
|
201
201
|
mysql_schema = Loader.mysql_table_definition(options)
|
202
202
|
vertica_schema = VerticaLoader.destination_table_vertica(options)
|
203
203
|
|
@@ -205,19 +205,16 @@ module Myreplicator
|
|
205
205
|
unless vertica_schema.size > 0
|
206
206
|
return {:changed => true, :mysql_schema => mysql_schema, :new => true}
|
207
207
|
end
|
208
|
-
Kernel.p "***** 1 *****"
|
209
208
|
# compare two schemas
|
210
209
|
|
211
210
|
|
212
211
|
mysql_schema_2 = get_mysql_schema_rows mysql_schema
|
213
212
|
if compare_schemas(vertica_schema, mysql_schema_2)
|
214
|
-
Kernel.p "***** 2 *****"
|
215
213
|
result = {:changed => true, :mysql_schema => mysql_schema, :vertica_schema => vertica_schema,:new => false}
|
216
214
|
else
|
217
|
-
Kernel.p "***** 3 *****"
|
218
215
|
result = {:changed => false, :mysql_schema => mysql_schema}
|
219
216
|
end
|
220
|
-
Kernel.p result
|
217
|
+
#Kernel.p result
|
221
218
|
return result
|
222
219
|
end
|
223
220
|
|
@@ -145,17 +145,17 @@ module Myreplicator
|
|
145
145
|
# Location of the output file needs to have 777 perms
|
146
146
|
##
|
147
147
|
def self.mysql_export_outfile *args
|
148
|
-
Kernel.p "===== mysql_export_outfile OPTIONS ====="
|
148
|
+
#Kernel.p "===== mysql_export_outfile OPTIONS ====="
|
149
149
|
|
150
150
|
options = args.extract_options!
|
151
|
-
Kernel.p options
|
151
|
+
#Kernel.p options
|
152
152
|
options.reverse_merge! :flags => []
|
153
153
|
db = options[:source_schema]
|
154
154
|
|
155
155
|
# Database host when ssh'ed into the db server
|
156
156
|
db_host = "127.0.0.1"
|
157
|
-
Kernel.p "===== mysql_export_outfile ssh_configs ====="
|
158
|
-
Kernel.p ssh_configs(db)
|
157
|
+
#Kernel.p "===== mysql_export_outfile ssh_configs ====="
|
158
|
+
#Kernel.p ssh_configs(db)
|
159
159
|
if !ssh_configs(db)["ssh_db_host"].blank?
|
160
160
|
db_host = ssh_configs(db)["ssh_db_host"]
|
161
161
|
elsif !db_configs(db)["host"].blank?
|
data/lib/loader/loader.rb
CHANGED
@@ -33,11 +33,11 @@ module Myreplicator
|
|
33
33
|
incrementals = []
|
34
34
|
all_files = Myreplicator::Loader.metadata_files
|
35
35
|
|
36
|
-
Kernel.p "===== all_files ====="
|
37
|
-
Kernel.p all_files
|
36
|
+
#Kernel.p "===== all_files ====="
|
37
|
+
#Kernel.p all_files
|
38
38
|
|
39
39
|
all_files.each do |m|
|
40
|
-
Kernel.p m
|
40
|
+
#Kernel.p m
|
41
41
|
if m.export_type == "initial"
|
42
42
|
initials << m # Add initial to the list
|
43
43
|
all_files.delete(m) # Delete obj from mixed list
|
@@ -53,11 +53,42 @@ module Myreplicator
|
|
53
53
|
|
54
54
|
incrementals = all_files # Remaining are all incrementals
|
55
55
|
|
56
|
-
initial_procs = Loader.initial_loads initials
|
57
|
-
parallel_load initial_procs
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
#initial_procs = Loader.initial_loads initials
|
57
|
+
#parallel_load initial_procs
|
58
|
+
initials.each do |metadata|
|
59
|
+
Myreplicator::Log.run(:job_type => "loader",
|
60
|
+
:name => "#{metadata.export_type}_import",
|
61
|
+
:file => metadata.filename,
|
62
|
+
:export_id => metadata.export_id) do |log|
|
63
|
+
if Myreplicator::Loader.transfer_completed? metadata
|
64
|
+
if metadata.export_to == "vertica"
|
65
|
+
Myreplicator::Loader.incremental_load metadata
|
66
|
+
else
|
67
|
+
Myreplicator::Loader.initial_load metadata
|
68
|
+
end
|
69
|
+
Myreplicator::Loader.cleanup metadata
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#incremental_procs = Loader.incremental_loads incrementals
|
75
|
+
#parallel_load incremental_procs
|
76
|
+
#groups = Myreplicator::Loader.group_incrementals incrementals
|
77
|
+
#groups.each do |group|
|
78
|
+
incrementals.each do |metadata|
|
79
|
+
Myreplicator::Log.run(:job_type => "loader",
|
80
|
+
:name => "incremental_import",
|
81
|
+
:file => metadata.filename,
|
82
|
+
:export_id => metadata.export_id) do |log|
|
83
|
+
if Myreplicator::Loader.transfer_completed? metadata
|
84
|
+
Myreplicator::Loader.incremental_load metadata
|
85
|
+
Myreplicator::Loader.cleanup metadata
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
# end # group
|
90
|
+
#end # groups
|
91
|
+
|
61
92
|
end
|
62
93
|
|
63
94
|
def self.parallel_load procs
|
@@ -78,18 +109,18 @@ module Myreplicator
|
|
78
109
|
|
79
110
|
initials.each do |metadata|
|
80
111
|
procs << Proc.new {
|
81
|
-
Log.run(:job_type => "loader",
|
112
|
+
Myreplicator::Log.run(:job_type => "loader",
|
82
113
|
:name => "#{metadata.export_type}_import",
|
83
114
|
:file => metadata.filename,
|
84
115
|
:export_id => metadata.export_id) do |log|
|
85
116
|
|
86
|
-
if Loader.transfer_completed? metadata
|
117
|
+
if Myreplicator::Loader.transfer_completed? metadata
|
87
118
|
if metadata.export_to == "vertica"
|
88
|
-
Loader.incremental_load metadata
|
119
|
+
Myreplicator::Loader.incremental_load metadata
|
89
120
|
else
|
90
|
-
Loader.initial_load metadata
|
121
|
+
Myreplicator::Loader.initial_load metadata
|
91
122
|
end
|
92
|
-
Loader.cleanup metadata
|
123
|
+
Myreplicator::Loader.cleanup metadata
|
93
124
|
end
|
94
125
|
|
95
126
|
end
|
@@ -110,14 +141,14 @@ module Myreplicator
|
|
110
141
|
groups.each do |group|
|
111
142
|
procs << Proc.new {
|
112
143
|
group.each do |metadata|
|
113
|
-
Log.run(:job_type => "loader",
|
144
|
+
Myreplicator::Log.run(:job_type => "loader",
|
114
145
|
:name => "incremental_import",
|
115
146
|
:file => metadata.filename,
|
116
147
|
:export_id => metadata.export_id) do |log|
|
117
148
|
|
118
|
-
if Loader.transfer_completed? metadata
|
119
|
-
Loader.incremental_load metadata
|
120
|
-
Loader.cleanup metadata
|
149
|
+
if Myreplicator::Loader.transfer_completed? metadata
|
150
|
+
Myreplicator::Loader.incremental_load metadata
|
151
|
+
Myreplicator::Loader.cleanup metadata
|
121
152
|
end
|
122
153
|
|
123
154
|
end
|
@@ -231,10 +262,10 @@ module Myreplicator
|
|
231
262
|
# being loaded is completed
|
232
263
|
##
|
233
264
|
def self.transfer_completed? metadata
|
234
|
-
Kernel.p "===== transfer_completed? metadata ====="
|
235
|
-
Kernel.p ({:export_id => metadata.export_id,
|
236
|
-
|
237
|
-
|
265
|
+
#Kernel.p "===== transfer_completed? metadata ====="
|
266
|
+
#Kernel.p ({:export_id => metadata.export_id,
|
267
|
+
# :file => metadata.export_path,
|
268
|
+
#:job_type => "transporter"})
|
238
269
|
if Log.completed?(:export_id => metadata.export_id,
|
239
270
|
:file => metadata.export_path,
|
240
271
|
:job_type => "transporter")
|
@@ -283,26 +314,26 @@ module Myreplicator
|
|
283
314
|
files << ExportMetadata.new(:metadata_path => json_file)
|
284
315
|
end
|
285
316
|
result = []
|
286
|
-
Kernel.p files
|
317
|
+
#Kernel.p files
|
287
318
|
files.each do |file|
|
288
|
-
puts "<<<<<<<<<<<<<<<<"
|
319
|
+
#puts "<<<<<<<<<<<<<<<<"
|
289
320
|
job = Export.where("id = #{file.export_id}").first
|
290
|
-
puts "<<<<<<<<<<<<<<<<"
|
291
|
-
Kernel.p job
|
292
|
-
puts "<<<<<<<<<<<<<<<<"
|
293
|
-
puts "&&&&&&&&&&&&&&&&&&&&&&&&&&"
|
294
|
-
Kernel.p file
|
295
|
-
puts "&&&&&&&&&&&&&&&&&&&&&&&&&&"
|
321
|
+
#puts "<<<<<<<<<<<<<<<<"
|
322
|
+
#Kernel.p job
|
323
|
+
#puts "<<<<<<<<<<<<<<<<"
|
324
|
+
#puts "&&&&&&&&&&&&&&&&&&&&&&&&&&"
|
325
|
+
#Kernel.p file
|
326
|
+
#puts "&&&&&&&&&&&&&&&&&&&&&&&&&&"
|
296
327
|
#if job.state == "transport_completed"
|
297
|
-
|
328
|
+
result << file
|
298
329
|
#end
|
299
|
-
puts "^^^^^^^^^^^^^^^^^^^^^^^^^^"
|
300
|
-
Kernel.p result
|
301
|
-
puts "^^^^^^^^^^^^^^^^^^^^^^^^^^"
|
330
|
+
#puts "^^^^^^^^^^^^^^^^^^^^^^^^^^"
|
331
|
+
#Kernel.p result
|
332
|
+
#puts "^^^^^^^^^^^^^^^^^^^^^^^^^^"
|
302
333
|
end
|
303
|
-
puts "<<<<<<<<<<<<<<<<"
|
334
|
+
#puts "<<<<<<<<<<<<<<<<"
|
304
335
|
|
305
|
-
puts "<<<<<<<<<<<<<<<<"
|
336
|
+
#puts "<<<<<<<<<<<<<<<<"
|
306
337
|
return result
|
307
338
|
end
|
308
339
|
|
@@ -313,9 +344,9 @@ module Myreplicator
|
|
313
344
|
##
|
314
345
|
def self.clear_older_files metadata
|
315
346
|
files = Loader.metadata_files
|
316
|
-
Kernel.p "===== clear old files ====="
|
317
|
-
Kernel.p metadata
|
318
|
-
Kernel.p files
|
347
|
+
#Kernel.p "===== clear old files ====="
|
348
|
+
#Kernel.p metadata
|
349
|
+
#Kernel.p files
|
319
350
|
max_date = DateTime.strptime metadata.export_time
|
320
351
|
files.each do |m|
|
321
352
|
if metadata.export_id == m.export_id
|
data/lib/myreplicator/version.rb
CHANGED
@@ -52,8 +52,45 @@ module Myreplicator
|
|
52
52
|
# Kicks off parallel download
|
53
53
|
##
|
54
54
|
def self.download export
|
55
|
-
Kernel.p "===== 1 ====="
|
56
|
-
parallel_download(completed_files(export))
|
55
|
+
#Kernel.p "===== 1 ====="
|
56
|
+
#parallel_download(completed_files(export))
|
57
|
+
files = completed_files(export)
|
58
|
+
files.each do |f|
|
59
|
+
export = f[:export]
|
60
|
+
filename = f[:file]
|
61
|
+
ActiveRecord::Base.verify_active_connections!
|
62
|
+
ActiveRecord::Base.connection.reconnect!
|
63
|
+
|
64
|
+
Log.run(:job_type => "transporter", :name => "metadata_file",
|
65
|
+
:file => filename, :export_id => export.id ) do |log|
|
66
|
+
|
67
|
+
sftp = export.sftp_to_source
|
68
|
+
json_file = Transporter.remote_path(export, filename)
|
69
|
+
json_local_path = File.join(tmp_dir,filename)
|
70
|
+
puts "Downloading #{json_file}"
|
71
|
+
sftp.download!(json_file, json_local_path)
|
72
|
+
metadata = Transporter.metadata_obj(json_local_path)
|
73
|
+
dump_file = metadata.export_path
|
74
|
+
puts metadata.state
|
75
|
+
if metadata.state == "export_completed"
|
76
|
+
Log.run(:job_type => "transporter", :name => "export_file",
|
77
|
+
:file => dump_file, :export_id => export.id) do |log|
|
78
|
+
puts "Downloading #{dump_file}"
|
79
|
+
local_dump_file = File.join(tmp_dir, dump_file.split("/").last)
|
80
|
+
sftp.download!(dump_file, local_dump_file)
|
81
|
+
Transporter.remove!(export, json_file, dump_file)
|
82
|
+
#export.update_attributes!({:state => 'transport_completed'})
|
83
|
+
# store back up as well
|
84
|
+
unless metadata.store_in.blank?
|
85
|
+
Transporter.backup_files(metadata.backup_path, json_local_path, local_dump_file)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
else
|
89
|
+
# TO DO: remove metadata file of failed export
|
90
|
+
Transporter.remove!(export, json_file, "")
|
91
|
+
end #if
|
92
|
+
end
|
93
|
+
end
|
57
94
|
end
|
58
95
|
|
59
96
|
##
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myreplicator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.21
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03
|
12
|
+
date: 2013-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -357,7 +357,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
357
357
|
version: '0'
|
358
358
|
segments:
|
359
359
|
- 0
|
360
|
-
hash:
|
360
|
+
hash: -1843574403921129739
|
361
361
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
362
362
|
none: false
|
363
363
|
requirements:
|
@@ -366,7 +366,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
366
366
|
version: '0'
|
367
367
|
segments:
|
368
368
|
- 0
|
369
|
-
hash:
|
369
|
+
hash: -1843574403921129739
|
370
370
|
requirements: []
|
371
371
|
rubyforge_project:
|
372
372
|
rubygems_version: 1.8.24
|