mysql_truck 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,61 +27,75 @@ module MysqlTruck
27
27
  @time = Time.new(*backup_date_str.split("-"))
28
28
  initialize_directories
29
29
 
30
- puts "Download & gunzip backups"
31
- puts "-------------------"
30
+ # puts "Download & gunzip backups"
31
+ # puts "-------------------"
32
32
 
33
33
 
34
- @bucket.keys(:prefix => s3_path).each do |key|
35
- puts "\n#{key}"
36
- next unless (filename = download_file(key))
34
+ # @bucket.keys(:prefix => s3_path).each do |key|
35
+ # next unless (filename = download_file(key))
37
36
 
38
- # gunzip file
39
- if tmp_path.join(filename).exist?
40
- print " - Inflating #{filename} ... "
41
- time = benchmark { `gunzip -f #{tmp_path.join(filename)}` }
42
- print "complete (#{formatted_time time}).\n"
43
- end
44
- end
37
+ # # gunzip file
38
+ # if tmp_path.join(filename).exist?
39
+ # print " - Inflating #{filename} ... "
40
+ # time = benchmark { `gunzip -f #{tmp_path.join(filename)}` }
41
+ # print "complete (#{formatted_time time}).\n"
42
+ # end
43
+ # end
45
44
 
46
45
  # Load data
47
46
  puts "\nLoading schema and data by table"
48
47
  puts "--------------------------------"
49
-
50
- files = Dir["#{tmp_path}/*.no_index.sql"]
51
- total = files.size
48
+
49
+ files = Dir["#{tmp_path}/*"]
50
+ tables = files.map { |f| File.basename(f, File.extname(f)).to_s }.uniq
51
+ total = tables.size
52
52
  count = 0
53
53
 
54
- # Find all .no_index.sql files and process
55
- files.sort.each do |file|
54
+ # Find all table names and process
55
+ tables.sort.each do |table|
56
56
  count += 1
57
- table = File.basename(file, ".no_index.sql")
58
-
59
57
  puts "\nProcessing #{table} (#{count}/#{total})"
60
58
 
61
- schema_file = Pathname.new(file)
62
- index_file = tmp_path.join("#{table}.indices.sql")
63
- data_file = tmp_path.join("#{table}.data.sql")
64
- csv_data_file = tmp_path.join("#{table}.csv")
59
+ old_schema_file = tmp_path.join("#{table}.sql")
60
+ schema_file = tmp_path.join("#{table}.no_index.sql")
61
+ index_file = tmp_path.join("#{table}.indices.sql")
62
+ data_file = tmp_path.join("#{table}.data.sql")
63
+ csv_data_file = tmp_path.join("#{table}.csv")
64
+
65
+
66
+ if schema_file.exist?
67
+ print " - Loading schema: #{File.basename(schema_file)} ... "
68
+ execute_sql_file(table, backup_date_str, schema_file)
69
+ schema_file.delete
70
+
71
+ elsif old_schema_file.exist?
72
+ print " - Loading schema: #{File.basename(old_schema_file)} ... "
73
+ execute_sql_file(table, backup_date_str, old_schema_file)
74
+ old_schema_file.delete
75
+
76
+ else
77
+ puts "ERROR: no schema file!"
78
+ next
79
+ end
65
80
 
66
- print " - Loading schema for #{table} ... "
67
- execute_sql_file(table, backup_date_str, schema_file)
68
- schema_file.delete if schema_file.exist?
69
81
 
70
82
  if data_file.exist?
71
- print " - Importing #{schema_file.basename(".data.sql")} ... "
83
+ print " - Importing #{File.basename(data_file)} ... "
72
84
  execute_sql_file(table, backup_date_str, data_file)
85
+ data_file.delete
86
+
73
87
  elsif csv_data_file.exist?
74
- print " - Importing #{schema_file.basename(".csv")} ... "
75
- import_csv_file(table, backup_date_str, csv_data_file)
88
+ print " - Importing #{File.basename(csv_data_file)} ... "
89
+ csv_data_file = import_csv_file(table, backup_date_str, csv_data_file)
90
+ File.delete(csv_data_file)
76
91
  end
77
92
 
78
- data_file.delete if data_file.exist?
79
-
80
93
  if index_file.exist?
81
- print " - Adding indices for #{schema_file.basename(".no_index.sql")} ... "
94
+ print " - Adding indices: #{File.basename(index_file)} ... "
82
95
  execute_sql_file(table, backup_date_str, index_file)
96
+ index_file.delete
83
97
  end
84
- index_file.delete if index_file.exist?
98
+
85
99
  end
86
100
 
87
101
  puts "Backup loaded."
@@ -120,16 +134,19 @@ module MysqlTruck
120
134
  end
121
135
 
122
136
  print "complete (#{formatted_time time}).\n"
137
+
138
+ file_path
123
139
  end
124
140
 
125
141
  def download_file(key)
126
142
  filename = File.basename(key.name)
127
143
 
128
144
  unless should_download_file?(filename)
129
- puts " [ SKIP ]"
130
145
  return
131
146
  end
132
147
 
148
+ puts "\n#{key}"
149
+
133
150
  file = tmp_path.join(filename)
134
151
  unzipped_file = tmp_path.join(file.basename(".gz"))
135
152
  if !smartly? || (smartly? && !unzipped_file.exist?)
@@ -1,3 +1,3 @@
1
1
  module MysqlTruck
2
- VERSION = "0.5.5"
2
+ VERSION = "0.5.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_truck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-12-11 00:00:00.000000000 Z
14
+ date: 2012-12-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: right_aws