mysql_truck 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +3 -0
- data/lib/mysql_truck/loader.rb +18 -24
- data/lib/mysql_truck/version.rb +1 -1
- metadata +2 -1
data/README
ADDED
data/lib/mysql_truck/loader.rb
CHANGED
@@ -67,39 +67,21 @@ module MysqlTruck
|
|
67
67
|
index_file = tmp_path.join("#{table}.indices.sql")
|
68
68
|
data_file = tmp_path.join("#{table}.data.sql")
|
69
69
|
|
70
|
-
|
71
70
|
print " - Loading schema for #{table} ... "
|
72
|
-
|
73
|
-
|
74
|
-
print "complete (#{formatted_time time}).\n"
|
71
|
+
execute_sql_file(table, backup_date_str, schema_file)
|
72
|
+
schema_file.delete if schema_file.exist?
|
75
73
|
|
76
74
|
if data_file.exist?
|
77
75
|
print " - Importing #{schema_file.basename(".sql")} ... "
|
78
|
-
|
79
|
-
commands = ["cat #{data_file}"]
|
80
|
-
if config[:date_suffix]
|
81
|
-
commands << "sed 's/INTO #{table}/INTO #{table}_#{backup_date_str.gsub(/-/, "")}/g'"
|
82
|
-
end
|
83
|
-
commands << "mysql #{db_connection_options}"
|
84
|
-
|
85
|
-
time = benchmark do
|
86
|
-
`#{commands.join(" | ")}`
|
87
|
-
end
|
88
|
-
print "complete (#{formatted_time time}).\n"
|
76
|
+
execute_sql_file(table, backup_date_str, data_file)
|
89
77
|
end
|
78
|
+
data_file.delete if data_file.exist?
|
90
79
|
|
91
80
|
if index_file.exist?
|
92
81
|
print " - Adding indices for #{schema_file.basename(".no_index.sql")} ... "
|
93
|
-
|
94
|
-
time = benchmark do
|
95
|
-
`#{cmd}`
|
96
|
-
end
|
97
|
-
print "complete (#{formatted_time time}).\n"
|
82
|
+
execute_sql_file(table, backup_date_str, index_file)
|
98
83
|
end
|
99
|
-
|
100
|
-
schema_file.delete if schema_file.exist?
|
101
|
-
index_file.delete if index_file.exist?
|
102
|
-
data_file.delete if data_file.exist?
|
84
|
+
index_file.delete if index_file.exist?
|
103
85
|
end
|
104
86
|
|
105
87
|
puts "Backup loaded."
|
@@ -113,6 +95,18 @@ module MysqlTruck
|
|
113
95
|
puts e.backtrace.join("\n")
|
114
96
|
end
|
115
97
|
|
98
|
+
def execute_sql_file(table, backup_date_str, file_path)
|
99
|
+
cat_cmd = "cat #{file_path}"
|
100
|
+
sed_cmd = config[:date_suffix ] ? "sed 's/`#{table}`/`#{table}_#{backup_date_str.gsub(/-/, "")}`/g'" : nil
|
101
|
+
sed2_cmd = config[:date_suffix ] ? "sed 's/TABLE #{table}/TABLE #{table}_#{backup_date_str.gsub(/-/, "")}/g'" : nil
|
102
|
+
import_cmd = "mysql #{db_connection_options}"
|
103
|
+
|
104
|
+
time = benchmark do
|
105
|
+
`#{[ cat_cmd, sed_cmd, sed2_cmd, import_cmd].compact.join(' | ')}`
|
106
|
+
end
|
107
|
+
print "complete (#{formatted_time time}).\n"
|
108
|
+
end
|
109
|
+
|
116
110
|
def download_file(key)
|
117
111
|
filename = File.basename(key.name)
|
118
112
|
|
data/lib/mysql_truck/version.rb
CHANGED
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.
|
4
|
+
version: 0.5.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -40,6 +40,7 @@ extra_rdoc_files: []
|
|
40
40
|
files:
|
41
41
|
- .gitignore
|
42
42
|
- Gemfile
|
43
|
+
- README
|
43
44
|
- Rakefile
|
44
45
|
- TODO
|
45
46
|
- bin/mysql_truck
|