dumpr 1.3 → 1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.md +27 -0
- data/lib/dumpr/cli.rb +121 -60
- data/lib/dumpr/driver.rb +2 -1
- data/lib/dumpr/driver/mysql.rb +10 -1
- data/lib/dumpr/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8c02ade1ba736e8679ffb7e54cc5f3413ba308d62cfdc86eeea60bc62cd474dd
|
4
|
+
data.tar.gz: eb764153537a887343fd494a66c27d0aa5c298126b4c29b645954086af245b8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87329f584c23b6a5370b3f3259ec83c0813f8bded0ee1621defd3832cbe1d30ebad7b438c5216e5999cea4ead19178d05bb199d54b88f99503aa6b3eec549391
|
7
|
+
data.tar.gz: af346b6d5a243d1c078007911e8c9edc4d3a90276dcd791b5cd78bd81ada6434719a5b8e37d24e381c4f57b48b9ead02ea70d9e820883a9fe348f6c6f0d6e554
|
data/History.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# HISTORY
|
2
|
+
|
3
|
+
This is the changelog version history for the dumpr gem.
|
4
|
+
|
5
|
+
## dumpr 1.4
|
6
|
+
|
7
|
+
* Changed `--password` to no longer be required.
|
8
|
+
* Improved `--help` documentation.
|
9
|
+
|
10
|
+
## dumpr 1.3
|
11
|
+
|
12
|
+
* Added support for postgresql with `-t postgres`
|
13
|
+
|
14
|
+
## dumpr 1.2
|
15
|
+
|
16
|
+
* Changed repo name from dumper to dumpr for uniqueness sake.
|
17
|
+
* Added command `dumpr-import`.
|
18
|
+
* Deprecated `dumpr -i` option, replaced by `dumpr-import`.
|
19
|
+
|
20
|
+
## dumpr 1.0
|
21
|
+
|
22
|
+
* Better usage
|
23
|
+
|
24
|
+
|
25
|
+
## dumpr 1.0
|
26
|
+
|
27
|
+
* Initial release.
|
data/lib/dumpr/cli.rb
CHANGED
@@ -18,15 +18,27 @@ module Dumpr
|
|
18
18
|
op = OptionParser.new do |opts|
|
19
19
|
|
20
20
|
opts.banner = <<-ENDSTR
|
21
|
-
|
21
|
+
#{PROG_NAME} #{Dumpr::Version}
|
22
22
|
|
23
|
-
|
23
|
+
usage: #{PROG_NAME} [options] [file]
|
24
24
|
|
25
|
-
|
25
|
+
#{PROG_NAME} --user test --db test_example test_example_dump.sql
|
26
26
|
|
27
|
-
|
27
|
+
Create a database dump file, exporting database(s) to a file.
|
28
|
+
The default database type is MySQL. Supports MySQL and Postgres.
|
28
29
|
|
29
|
-
|
30
|
+
arguments:
|
31
|
+
|
32
|
+
[file] File is the filename of the database dump being created.
|
33
|
+
It may be relative, 'mydumpfile.sql' to write to your working directory.
|
34
|
+
It may be absolute, 'server:/path/to/dumpfile.sql'.
|
35
|
+
If server: is specified, ssh/scp is used to transfer data to the remote server.
|
36
|
+
You will want to setup .ssh/config to avoid being prompted for passwords.
|
37
|
+
The .gz file extension is assumed.
|
38
|
+
By default it will first look for a compressed version at [file].gz.
|
39
|
+
The --no-gzip option can be used to skip compression.
|
40
|
+
|
41
|
+
options:
|
30
42
|
|
31
43
|
ENDSTR
|
32
44
|
|
@@ -34,20 +46,20 @@ ENDSTR
|
|
34
46
|
options[:driver] = val
|
35
47
|
end
|
36
48
|
|
37
|
-
opts.on("--
|
38
|
-
options[:all_databases] = val
|
39
|
-
end
|
40
|
-
|
41
|
-
opts.on("--db DATABASE", "--database DATABASE", "Database to dump/import") do |val|
|
49
|
+
opts.on("--db DATABASE", "--database DATABASE", "Dump a single database") do |val|
|
42
50
|
options[:database] = val
|
43
51
|
end
|
44
52
|
|
45
53
|
# TODO: Add support to Driver for this
|
46
|
-
opts.on("--databases x,y,z", Array, "
|
54
|
+
opts.on("--databases x,y,z", Array, "Dump multiple databases") do |val|
|
47
55
|
options[:databases] = val
|
48
56
|
end
|
49
57
|
|
50
|
-
opts.on("--
|
58
|
+
opts.on("--all-databases", "Dump ALL databases") do |val|
|
59
|
+
options[:all_databases] = val
|
60
|
+
end
|
61
|
+
|
62
|
+
opts.on("--tables z,y,z", Array, "Dump certain tables, to be used on conjuction with a single --database") do |val|
|
51
63
|
options[:tables] = val
|
52
64
|
end
|
53
65
|
|
@@ -67,23 +79,25 @@ ENDSTR
|
|
67
79
|
options[:port] = val
|
68
80
|
end
|
69
81
|
|
70
|
-
opts.on("--file FILENAME", "Filename of dump to create
|
82
|
+
opts.on("-f FILENAME", "--file FILENAME", "Filename of dump to create, may passed in place of the [file] argument.") do |val|
|
71
83
|
options[:dumpfile] = val
|
72
84
|
end
|
73
85
|
|
74
|
-
|
75
|
-
options[:dumpfile] = val
|
76
|
-
end
|
86
|
+
# could get rid of all these and just rely on full filepath being passed.
|
77
87
|
|
78
|
-
opts.on("--
|
79
|
-
|
80
|
-
end
|
88
|
+
# opts.on("--dumpfile FILENAME", "Alias for --file") do |val|
|
89
|
+
# options[:dumpfile] = val
|
90
|
+
# end
|
81
91
|
|
82
|
-
opts.on("--
|
83
|
-
|
84
|
-
end
|
92
|
+
# opts.on("--destination DESTINATION", "Destination for dumpfile. This can be a remote host:path.") do |val|
|
93
|
+
# options[:destination] = val
|
94
|
+
# end
|
85
95
|
|
86
|
-
opts.on("--
|
96
|
+
# opts.on("--dumpdir DIRECTORY", "Default directory for dumpfiles. Default is working directory") do |val|
|
97
|
+
# options[:dumpdir] = val
|
98
|
+
# end
|
99
|
+
|
100
|
+
opts.on("--dump-options=[OPTIONS]", "Extra options to be included in dump command") do |val|
|
87
101
|
options[:dump_options] = val
|
88
102
|
end
|
89
103
|
|
@@ -105,6 +119,7 @@ ENDSTR
|
|
105
119
|
|
106
120
|
opts.on("-h", "--help", "Show this message") do
|
107
121
|
puts opts
|
122
|
+
print "\n"
|
108
123
|
exit
|
109
124
|
end
|
110
125
|
|
@@ -117,9 +132,22 @@ ENDSTR
|
|
117
132
|
|
118
133
|
begin
|
119
134
|
op.parse!(args)
|
120
|
-
|
121
|
-
|
122
|
-
|
135
|
+
if args.count == 0 && options[:dumpfile].nil?
|
136
|
+
raise OptionParser::InvalidOption.new("[file] or --file is required.")
|
137
|
+
elsif args.count == 1
|
138
|
+
options[:dumpfile] = args[0]
|
139
|
+
else
|
140
|
+
raise OptionParser::NeedlessArgument.new("wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.join(', ')}")
|
141
|
+
end
|
142
|
+
rescue => e
|
143
|
+
case (e)
|
144
|
+
when OptionParser::InvalidOption, OptionParser::AmbiguousOption, OptionParser::MissingArgument, OptionParser::InvalidArgument, OptionParser::NeedlessArgument
|
145
|
+
STDERR.puts "#{e.message}"
|
146
|
+
STDERR.puts "Try -h for help with this command."
|
147
|
+
exit 1
|
148
|
+
else
|
149
|
+
raise e
|
150
|
+
end
|
123
151
|
end
|
124
152
|
|
125
153
|
|
@@ -133,7 +161,7 @@ ENDSTR
|
|
133
161
|
puts "bad arguments: #{e.message}.\n See --help"
|
134
162
|
exit 1
|
135
163
|
rescue Dumpr::DumpFileExists => e
|
136
|
-
puts "#{e.message}\nIt looks like this dump exists already. You should move it, or use --force to
|
164
|
+
puts "#{e.message}\nIt looks like this dump exists already. You should move it, or use --force to overwrite it"
|
137
165
|
exit 1
|
138
166
|
rescue Dumpr::BusyDumping => e
|
139
167
|
puts "#{e.message}\n See --help"
|
@@ -159,15 +187,31 @@ ENDSTR
|
|
159
187
|
op = OptionParser.new do |opts|
|
160
188
|
|
161
189
|
opts.banner = <<-ENDSTR
|
162
|
-
|
190
|
+
#{PROG_NAME} #{Dumpr::Version}
|
191
|
+
|
192
|
+
usage:
|
193
|
+
#{PROG_NAME} [options] [file]
|
163
194
|
|
164
|
-
|
195
|
+
#{PROG_NAME} --user test --db test_example ./test_example_dump.sql
|
165
196
|
|
166
|
-
|
197
|
+
Import a database dump file, restoring data to the specified hosts and database(s).
|
198
|
+
The default database type is MySQL. Supports MySQL and Postgres.
|
199
|
+
WARNING: This command will overwrite your database information.
|
200
|
+
Be sure you specify the correct host and database name(s)
|
201
|
+
and the [file] that contains the data you want in it.
|
167
202
|
|
168
|
-
|
203
|
+
arguments:
|
169
204
|
|
170
|
-
|
205
|
+
[file] File is the path of the database dump file being imported.
|
206
|
+
File may be relative, 'mydumpfile.sql.gz' to read from your working directory.
|
207
|
+
File may be absolute, 'server:/path/to/dumpfile.sql'.
|
208
|
+
If server: is specified, ssh/scp is used to transfer data from the remote server.
|
209
|
+
You will want to setup ssh configuration to avoid password prompts.
|
210
|
+
The .gz file extension is assumed.
|
211
|
+
By default it will first look for a compressed version at [file].gz.
|
212
|
+
The --no-gzip option can be used to skip compression.
|
213
|
+
|
214
|
+
options:
|
171
215
|
|
172
216
|
ENDSTR
|
173
217
|
|
@@ -175,23 +219,24 @@ ENDSTR
|
|
175
219
|
options[:driver] = val
|
176
220
|
end
|
177
221
|
|
178
|
-
opts.on("--
|
179
|
-
options[:all_databases] = val
|
180
|
-
end
|
181
|
-
|
182
|
-
opts.on("--db DATABASE", "--database DATABASE", "Database to dump/import") do |val|
|
222
|
+
opts.on("--db DATABASE", "--database DATABASE", "Import to a single database") do |val|
|
183
223
|
options[:database] = val
|
184
224
|
end
|
185
225
|
|
186
|
-
# TODO:
|
187
|
-
|
226
|
+
# TODO: add support to Driver for --databases and --tables
|
227
|
+
# import probably does not need this right now
|
228
|
+
opts.on("--databases x,y,z", Array, "Import multiple databases") do |val|
|
188
229
|
options[:databases] = val
|
189
230
|
end
|
190
231
|
|
191
|
-
opts.on("--
|
192
|
-
options[:
|
232
|
+
opts.on("--all-databases", "Import ALL databases") do |val|
|
233
|
+
options[:all_databases] = val
|
193
234
|
end
|
194
235
|
|
236
|
+
# opts.on("--tables x,y,z", Array, "Import only certain tables, to be used on conjuction with a single --database") do |val|
|
237
|
+
# options[:tables] = val
|
238
|
+
# end
|
239
|
+
|
195
240
|
opts.on("-u USER", "--user USER", "Database user") do |val|
|
196
241
|
options[:user] = val
|
197
242
|
end
|
@@ -208,23 +253,25 @@ ENDSTR
|
|
208
253
|
options[:port] = val
|
209
254
|
end
|
210
255
|
|
211
|
-
opts.on("--file FILENAME", "Filename of dump to create
|
256
|
+
opts.on("-f FILENAME", "--file FILENAME", "Filename of dump to create, may passed in place of the [file] argument.") do |val|
|
212
257
|
options[:dumpfile] = val
|
213
258
|
end
|
214
259
|
|
215
|
-
|
216
|
-
options[:dumpfile] = val
|
217
|
-
end
|
260
|
+
# could get rid of all these and just rely on full filepath being passed.
|
218
261
|
|
219
|
-
opts.on("--
|
220
|
-
|
221
|
-
end
|
262
|
+
# opts.on("--dumpfile FILENAME", "Alias for --file") do |val|
|
263
|
+
# options[:dumpfile] = val
|
264
|
+
# end
|
222
265
|
|
223
|
-
opts.on("--
|
224
|
-
|
225
|
-
end
|
266
|
+
# opts.on("--destination DESTINATION", "Destination for dump files. This can be a remote host:path.") do |val|
|
267
|
+
# options[:destination] = val
|
268
|
+
# end
|
269
|
+
|
270
|
+
# opts.on("--dumpdir DIRECTORY", "Default directory for dump files. Default is working directory") do |val|
|
271
|
+
# options[:dumpdir] = val
|
272
|
+
# end
|
226
273
|
|
227
|
-
opts.on("--import-options=[
|
274
|
+
opts.on("--import-options=[OPTIONS]", "Extra options to be included in import command") do |val|
|
228
275
|
options[:import_options] = val.to_s
|
229
276
|
end
|
230
277
|
|
@@ -232,20 +279,21 @@ ENDSTR
|
|
232
279
|
options[:gzip] = false
|
233
280
|
end
|
234
281
|
|
235
|
-
opts.on("--gzip-options=[GZIPOPTIONS]", "gzip compression options. Default is -9 (slowest /max compression)") do |val|
|
236
|
-
|
237
|
-
end
|
282
|
+
# opts.on("--gzip-options=[GZIPOPTIONS]", "gzip compression options. Default is -9 (slowest /max compression)") do |val|
|
283
|
+
# options[:gzip_options] = val
|
284
|
+
# end
|
238
285
|
|
239
286
|
opts.on("--log-file LOGFILE", "Log file. Default is stdout.") do |val|
|
240
287
|
options[:log_file] = val
|
241
288
|
end
|
242
289
|
|
243
|
-
opts.on("--force", "Overwrite
|
290
|
+
opts.on("--force", "Overwrite dump file if it exists already.") do |val|
|
244
291
|
options[:force] = val
|
245
292
|
end
|
246
293
|
|
247
294
|
opts.on("-h", "--help", "Show this message") do
|
248
295
|
puts opts
|
296
|
+
print "\n"
|
249
297
|
exit
|
250
298
|
end
|
251
299
|
|
@@ -258,9 +306,22 @@ ENDSTR
|
|
258
306
|
|
259
307
|
begin
|
260
308
|
op.parse!(args)
|
261
|
-
|
262
|
-
|
263
|
-
|
309
|
+
if args.count == 0 && options[:dumpfile].nil?
|
310
|
+
raise OptionParser::InvalidOption.new("[file] or --file is required.")
|
311
|
+
elsif args.count == 1
|
312
|
+
options[:dumpfile] = args[0]
|
313
|
+
else
|
314
|
+
raise OptionParser::NeedlessArgument.new("wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.join(', ')}")
|
315
|
+
end
|
316
|
+
rescue => e
|
317
|
+
case (e)
|
318
|
+
when OptionParser::InvalidOption, OptionParser::AmbiguousOption, OptionParser::MissingArgument, OptionParser::InvalidArgument, OptionParser::NeedlessArgument
|
319
|
+
STDERR.puts "#{e.message}"
|
320
|
+
STDERR.puts "Try -h for help with this command."
|
321
|
+
exit 1
|
322
|
+
else
|
323
|
+
raise e
|
324
|
+
end
|
264
325
|
end
|
265
326
|
|
266
327
|
|
@@ -274,7 +335,7 @@ ENDSTR
|
|
274
335
|
puts "bad arguments: #{e.message}.\n See --help"
|
275
336
|
exit 1
|
276
337
|
rescue Dumpr::DumpFileExists => e
|
277
|
-
puts "#{e.message}\nIt looks like this dump exists already. You should move it, or use --force to
|
338
|
+
puts "#{e.message}\nIt looks like this dump exists already. You should move it, or use --force to overwrite it"
|
278
339
|
exit 1
|
279
340
|
rescue Dumpr::BusyDumping => e
|
280
341
|
puts "#{e.message}\n See --help"
|
data/lib/dumpr/driver.rb
CHANGED
@@ -66,7 +66,8 @@ module Dumpr
|
|
66
66
|
@gzip = opts[:gzip].nil? ? true : opts[:gzip]
|
67
67
|
@gzip_options = opts[:gzip_options] || "-9"
|
68
68
|
@dumpdir = opts[:dumpdir] || Dir.pwd #"./"
|
69
|
-
@dumpfile = (opts[:file] || opts[:dumpfile] || opts[:filename]) or raise BadConfig.new "
|
69
|
+
@dumpfile = (opts[:file] || opts[:dumpfile] || opts[:filename]) or raise BadConfig.new "[file] is required"
|
70
|
+
@dumpfile = @dumpfile.to_s.dup # this is frozen?
|
70
71
|
@dumpfile = @dumpfile[0].chr == "/" ? @dumpfile : File.join(@dumpdir, @dumpfile)
|
71
72
|
@dumpfile.chomp!(".gz")
|
72
73
|
# (optional) :destination is where dumps are exported to, and can be a remote host:path
|
data/lib/dumpr/driver/mysql.rb
CHANGED
@@ -43,7 +43,16 @@ module Dumpr
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def import_cmd
|
46
|
-
"mysql -u #{user} --password=#{password} -h #{host} -P #{port} #{database} < #{dumpfile}"
|
46
|
+
#"mysql -u #{user} --password=#{password} -h #{host} -P #{port} #{database} < #{dumpfile}"
|
47
|
+
cmd = ["mysql"]
|
48
|
+
cmd << "-u '#{user}'" unless user.to_s.empty?
|
49
|
+
cmd << "--password '#{password}'" unless password.to_s.empty?
|
50
|
+
cmd << "-h '#{host}'" unless host.to_s.empty?
|
51
|
+
cmd << "-P '#{port}'" unless port.to_s.empty?
|
52
|
+
cmd << "#{database}" unless database.empty?
|
53
|
+
cmd << "#{import_options}" unless import_options.to_s.empty?
|
54
|
+
cmd << " < #{dumpfile}"
|
55
|
+
cmd.join(" ")
|
47
56
|
end
|
48
57
|
|
49
58
|
end
|
data/lib/dumpr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dumpr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Dickson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Dumpr provides an easy way to dump and import databases. Supported databases
|
14
14
|
include MySQL and Postgres.
|
@@ -24,6 +24,7 @@ extra_rdoc_files:
|
|
24
24
|
files:
|
25
25
|
- ".gitignore"
|
26
26
|
- Gemfile
|
27
|
+
- History.md
|
27
28
|
- LICENSE
|
28
29
|
- README.md
|
29
30
|
- Rakefile
|
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
60
|
version: '0'
|
60
61
|
requirements: []
|
61
62
|
rubyforge_project:
|
62
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.7.6
|
63
64
|
signing_key:
|
64
65
|
specification_version: 4
|
65
66
|
summary: Dump and import databases.
|