dumpr 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +16 -7
- data/bin/dumpr +1 -1
- data/bin/dumpr-import +4 -0
- data/dumpr.gemspec +3 -3
- data/lib/dumpr/cli.rb +149 -20
- data/lib/dumpr/driver.rb +5 -5
- data/lib/dumpr/driver/mysql.rb +13 -0
- data/lib/dumpr/driver/postgres.rb +58 -0
- data/lib/dumpr/version.rb +1 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 333617934d6bd6652bd3a67d8f5afdea20ab75d7
|
4
|
+
data.tar.gz: e738de1c4d150aba044599ac8842a33629df99c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb48d7a57b4424ebea2cedbf0b0d16995253e5c7d89df6bc555284a39befc58db0cc6ccdae4a9e8b2b7d77183e6a7ded49890448009aca281ef29ef28206d98e
|
7
|
+
data.tar.gz: fd08f9a6c8c81fc9d381cee212c3c73d0c04522ed77368ba057f6739d6c85704fce434819918dd1c959daaa8a847a07777d35ae6e0c5fbffcd4accbfa38044cd
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ Executables installed:
|
|
10
10
|
* dumpr
|
11
11
|
|
12
12
|
### Dependencies
|
13
|
-
* [Ruby ≥
|
13
|
+
* [Ruby ≥ 2.2.1](http://www.ruby-lang.org/en/downloads/)
|
14
14
|
|
15
15
|
**SSH access is assumed to be automated with .ssh/config entries**
|
16
16
|
|
@@ -39,7 +39,7 @@ Generate yourdb.sql.gz and transfer it to server2
|
|
39
39
|
|
40
40
|
Then, over on dbserver2, import your dump file
|
41
41
|
```sh
|
42
|
-
dumpr
|
42
|
+
dumpr-import --user user --password pw --file /data/dumps/yourdb.sql
|
43
43
|
```
|
44
44
|
|
45
45
|
## Ruby API
|
@@ -75,12 +75,21 @@ See *Dumpr::Driver*
|
|
75
75
|
|
76
76
|
## CHANGELOG
|
77
77
|
|
78
|
-
|
78
|
+
### Version 1.3
|
79
|
+
* Split binary, new command `dumpr-import` to replace `dumpr --import`
|
80
|
+
* Postgres support (beta)
|
79
81
|
|
80
|
-
|
82
|
+
### Version 1.2
|
83
|
+
* Changed gem and binary command from `dumper` to `dumpr`
|
84
|
+
|
85
|
+
### Version 1.1
|
86
|
+
* Tweaks
|
81
87
|
|
82
|
-
|
83
|
-
*
|
88
|
+
### Version 1.0
|
89
|
+
* Initial release
|
90
|
+
|
91
|
+
## TODO
|
92
|
+
* automate importing after an export (socket communication exporter/importer, or just lockfile checking / polling)
|
84
93
|
* security: stop logging passwords
|
85
|
-
* daemonize
|
94
|
+
* daemonize, maybe?
|
86
95
|
* SSH parameters
|
data/bin/dumpr
CHANGED
data/bin/dumpr-import
ADDED
data/dumpr.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["James Dickson"]
|
10
10
|
s.email = ["jdickson@bcap.com"]
|
11
|
-
s.homepage = "http://github.com/
|
12
|
-
s.summary = "Dump and
|
13
|
-
s.description = "Dumpr provides an easy way to dump and import databases."
|
11
|
+
s.homepage = "http://github.com/jamesdickson6/dumpr"
|
12
|
+
s.summary = "Dump and import databases."
|
13
|
+
s.description = "Dumpr provides an easy way to dump and import databases. Supported databases include MySQL and Postgres."
|
14
14
|
s.files = `git ls-files -z`.split("\x0")
|
15
15
|
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
16
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
data/lib/dumpr/cli.rb
CHANGED
@@ -7,7 +7,7 @@ module Dumpr
|
|
7
7
|
PROG_NAME = File.basename($0)
|
8
8
|
|
9
9
|
|
10
|
-
def self.
|
10
|
+
def self.dump(args)
|
11
11
|
# default options
|
12
12
|
options = {}
|
13
13
|
options[:dumpdir] = Dir.pwd
|
@@ -20,28 +20,20 @@ module Dumpr
|
|
20
20
|
opts.banner = <<-ENDSTR
|
21
21
|
Usage: #{PROG_NAME} [options]
|
22
22
|
|
23
|
-
|
23
|
+
Example:
|
24
24
|
|
25
25
|
#{PROG_NAME} --user root --password yourpass --db yourdb --file yourdb.sql --destination server2:/data/backups
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
#{PROG_NAME} -i --user root --password yourpass --db yourdb --file /data/backups/yourdb.sql
|
30
|
-
|
31
|
-
Don't forget to set up your .ssh/config so you won't be prompted for ssh passwords for file transfers
|
27
|
+
If using remote server destinations, don't forget to set up your .ssh/config so you won't be prompted for ssh passwords for file transfers.
|
32
28
|
|
33
29
|
Options:
|
34
30
|
|
35
31
|
ENDSTR
|
36
32
|
|
37
|
-
opts.on("-t", "--type
|
33
|
+
opts.on("-t", "--type TYPE", "Database type: mysql or postgres. Default is mysql.") do |val|
|
38
34
|
options[:driver] = val
|
39
35
|
end
|
40
36
|
|
41
|
-
opts.on("-i", "--import", "Import dump file. Default behavior is to dump and export to --destination") do |val|
|
42
|
-
options[:import] = val
|
43
|
-
end
|
44
|
-
|
45
37
|
opts.on("--all-databases", "dump/import ALL databases") do |val|
|
46
38
|
options[:all_databases] = val
|
47
39
|
end
|
@@ -51,11 +43,11 @@ ENDSTR
|
|
51
43
|
end
|
52
44
|
|
53
45
|
# TODO: Add support to Driver for this
|
54
|
-
opts.on("--databases
|
46
|
+
opts.on("--databases x,y,z", Array, "dump/import multiple databases") do |val|
|
55
47
|
options[:databases] = val
|
56
48
|
end
|
57
49
|
|
58
|
-
opts.on("--tables
|
50
|
+
opts.on("--tables z,y,z", Array, "dump certain tables, to be used on conjuction with a single --database") do |val|
|
59
51
|
options[:tables] = val
|
60
52
|
end
|
61
53
|
|
@@ -87,7 +79,7 @@ ENDSTR
|
|
87
79
|
options[:destination] = val
|
88
80
|
end
|
89
81
|
|
90
|
-
opts.on("--dumpdir", "Default directory for dumpfiles. Default is working directory") do |val|
|
82
|
+
opts.on("--dumpdir DIRECTORY", "Default directory for dumpfiles. Default is working directory") do |val|
|
91
83
|
options[:dumpdir] = val
|
92
84
|
end
|
93
85
|
|
@@ -103,7 +95,7 @@ ENDSTR
|
|
103
95
|
options[:gzip_options] = val
|
104
96
|
end
|
105
97
|
|
106
|
-
opts.on("--log-file
|
98
|
+
opts.on("--log-file LOGFILE", "Log file. Default is stdout.") do |val|
|
107
99
|
options[:log_file] = val
|
108
100
|
end
|
109
101
|
|
@@ -133,11 +125,148 @@ ENDSTR
|
|
133
125
|
|
134
126
|
# do it
|
135
127
|
begin
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
128
|
+
Dumpr.export(options[:driver], options)
|
129
|
+
rescue Dumpr::MissingDriver => e
|
130
|
+
puts "#{e.message}."
|
131
|
+
exit 1
|
132
|
+
rescue Dumpr::BadConfig => e
|
133
|
+
puts "bad arguments: #{e.message}.\n See --help"
|
134
|
+
exit 1
|
135
|
+
rescue Dumpr::DumpFileExists => e
|
136
|
+
puts "#{e.message}\nIt looks like this dump exists already. You should move it, or use --force to trash it"
|
137
|
+
exit 1
|
138
|
+
rescue Dumpr::BusyDumping => e
|
139
|
+
puts "#{e.message}\n See --help"
|
140
|
+
exit 1
|
141
|
+
rescue Dumpr::CommandFailure => e
|
142
|
+
puts e.message
|
143
|
+
exit 1
|
144
|
+
end
|
145
|
+
|
146
|
+
exit 0
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
def self.import(args)
|
152
|
+
# default options
|
153
|
+
options = {}
|
154
|
+
options[:dumpdir] = Dir.pwd
|
155
|
+
options[:driver] = :mysql
|
156
|
+
options[:gzip] = true
|
157
|
+
|
158
|
+
|
159
|
+
op = OptionParser.new do |opts|
|
160
|
+
|
161
|
+
opts.banner = <<-ENDSTR
|
162
|
+
Usage: #{PROG_NAME} [options]
|
163
|
+
|
164
|
+
Example:
|
165
|
+
|
166
|
+
#{PROG_NAME} -i --user root --password yourpass --db yourdb --file /data/backups/yourdb.sql
|
167
|
+
|
168
|
+
If using remote server destinations, don't forget to set up your .ssh/config so you won't be prompted for ssh passwords for file transfers.
|
169
|
+
|
170
|
+
Options:
|
171
|
+
|
172
|
+
ENDSTR
|
173
|
+
|
174
|
+
opts.on("-t", "--type TYPE", "Database type: mysql or postgres. Default is mysql.") do |val|
|
175
|
+
options[:driver] = val
|
176
|
+
end
|
177
|
+
|
178
|
+
opts.on("--all-databases", "dump/import ALL databases") do |val|
|
179
|
+
options[:all_databases] = val
|
180
|
+
end
|
181
|
+
|
182
|
+
opts.on("--db DATABASE", "--database DATABASE", "Database to dump/import") do |val|
|
183
|
+
options[:database] = val
|
184
|
+
end
|
185
|
+
|
186
|
+
# TODO: Add support to Driver for this
|
187
|
+
opts.on("--databases x,y,z", Array, "dump/import multiple databases") do |val|
|
188
|
+
options[:databases] = val
|
189
|
+
end
|
190
|
+
|
191
|
+
opts.on("--tables x,y,z", Array, "dump certain tables, to be used on conjuction with a single --database") do |val|
|
192
|
+
options[:tables] = val
|
193
|
+
end
|
194
|
+
|
195
|
+
opts.on("-u USER", "--user USER", "Database user") do |val|
|
196
|
+
options[:user] = val
|
140
197
|
end
|
198
|
+
|
199
|
+
opts.on("-p PASS", "--password PASS", "--password=pass", "Database password") do |val|
|
200
|
+
options[:password] = val
|
201
|
+
end
|
202
|
+
|
203
|
+
opts.on("-h HOST", "--host HOST", "Database host") do |val|
|
204
|
+
options[:host] = val
|
205
|
+
end
|
206
|
+
|
207
|
+
opts.on("-P PORT", "--port PORT", "Database port") do |val|
|
208
|
+
options[:port] = val
|
209
|
+
end
|
210
|
+
|
211
|
+
opts.on("--file FILENAME", "Filename of dump to create/import") do |val|
|
212
|
+
options[:dumpfile] = val
|
213
|
+
end
|
214
|
+
|
215
|
+
opts.on("--dumpfile FILENAME", "Alias for --file") do |val|
|
216
|
+
options[:dumpfile] = val
|
217
|
+
end
|
218
|
+
|
219
|
+
opts.on("--destination DESTINATION", "Destination for dumpfile. This can be a remote host:path.") do |val|
|
220
|
+
options[:destination] = val
|
221
|
+
end
|
222
|
+
|
223
|
+
opts.on("--dumpdir DIRECTORY", "Default directory for dumpfiles. Default is working directory") do |val|
|
224
|
+
options[:dumpdir] = val
|
225
|
+
end
|
226
|
+
|
227
|
+
opts.on("--import-options=[DUMPOPTIONS]", "Extra options to be included in dump command") do |val|
|
228
|
+
options[:import_options] = val.to_s
|
229
|
+
end
|
230
|
+
|
231
|
+
opts.on("--no-gzip", "Don't use gzip") do |val|
|
232
|
+
options[:gzip] = false
|
233
|
+
end
|
234
|
+
|
235
|
+
opts.on("--gzip-options=[GZIPOPTIONS]", "gzip compression options. Default is -9 (slowest /max compression)") do |val|
|
236
|
+
options[:gzip_options] = val
|
237
|
+
end
|
238
|
+
|
239
|
+
opts.on("--log-file LOGFILE", "Log file. Default is stdout.") do |val|
|
240
|
+
options[:log_file] = val
|
241
|
+
end
|
242
|
+
|
243
|
+
opts.on("--force", "Overwrite dumpfile if it exists already.") do |val|
|
244
|
+
options[:force] = val
|
245
|
+
end
|
246
|
+
|
247
|
+
opts.on("-h", "--help", "Show this message") do
|
248
|
+
puts opts
|
249
|
+
exit
|
250
|
+
end
|
251
|
+
|
252
|
+
opts.on("-v", "--version", "Show version") do
|
253
|
+
puts Dumpr::Version
|
254
|
+
exit
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
begin
|
260
|
+
op.parse!(args)
|
261
|
+
rescue OptionParser::MissingArgument => e
|
262
|
+
puts "invalid arguments. try #{PROG_NAME} --help"
|
263
|
+
exit 1
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
# do it
|
268
|
+
begin
|
269
|
+
Dumpr.import(options[:driver], options)
|
141
270
|
rescue Dumpr::MissingDriver => e
|
142
271
|
puts "#{e.message}."
|
143
272
|
exit 1
|
data/lib/dumpr/driver.rb
CHANGED
@@ -43,8 +43,8 @@ module Dumpr
|
|
43
43
|
# db connection settings
|
44
44
|
@host = opts[:host] || "localhost"
|
45
45
|
@port = opts[:port]
|
46
|
-
@user = opts[:user] or raise BadConfig.new "
|
47
|
-
@password = (opts[:password] || opts[:pass]) or raise BadConfig.new "
|
46
|
+
@user = opts[:user] or raise BadConfig.new "user is required"
|
47
|
+
@password = (opts[:password] || opts[:pass]) # or raise BadConfig.new "password is required"
|
48
48
|
|
49
49
|
# dump all_databases or specific database(s)
|
50
50
|
@all_databases = nil
|
@@ -59,14 +59,14 @@ module Dumpr
|
|
59
59
|
elsif opts[:all_databases]
|
60
60
|
@all_databases = true
|
61
61
|
else
|
62
|
-
raise BadConfig.new "
|
62
|
+
#raise BadConfig.new "database is required"
|
63
63
|
end
|
64
64
|
|
65
65
|
# dump settings
|
66
66
|
@gzip = opts[:gzip].nil? ? true : opts[:gzip]
|
67
67
|
@gzip_options = opts[:gzip_options] || "-9"
|
68
|
-
@dumpdir = opts[:dumpdir] || "./"
|
69
|
-
@dumpfile = (opts[:file] || opts[:dumpfile] || opts[:filename]) or raise BadConfig.new "
|
68
|
+
@dumpdir = opts[:dumpdir] || Dir.pwd #"./"
|
69
|
+
@dumpfile = (opts[:file] || opts[:dumpfile] || opts[:filename]) or raise BadConfig.new "dumpfile is required"
|
70
70
|
@dumpfile = @dumpfile[0].chr == "/" ? @dumpfile : File.join(@dumpdir, @dumpfile)
|
71
71
|
@dumpfile.chomp!(".gz")
|
72
72
|
# (optional) :destination is where dumps are exported to, and can be a remote host:path
|
data/lib/dumpr/driver/mysql.rb
CHANGED
@@ -19,6 +19,19 @@ module Dumpr
|
|
19
19
|
system("which mysql") == true
|
20
20
|
end
|
21
21
|
|
22
|
+
def configure(opts)
|
23
|
+
super(opts)
|
24
|
+
if @all_databases
|
25
|
+
# supported
|
26
|
+
elsif @databases
|
27
|
+
# supported
|
28
|
+
elsif @database
|
29
|
+
# supported
|
30
|
+
else
|
31
|
+
raise BadConfig.new "#{self.class} requires option --database or --databases or --all-databases"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
22
35
|
def dump_cmd
|
23
36
|
if @all_databases
|
24
37
|
"mysqldump -u #{user} --password=#{password} -h #{host} -P #{port} --all-databases #{dump_options}"
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'dumpr/driver'
|
2
|
+
module Dumpr
|
3
|
+
module Driver
|
4
|
+
class Postgres < Base
|
5
|
+
|
6
|
+
def port
|
7
|
+
@port || 5432
|
8
|
+
end
|
9
|
+
|
10
|
+
def dump_options
|
11
|
+
@dump_options || "-Fc" #"-Fc -v"
|
12
|
+
end
|
13
|
+
|
14
|
+
def dump_installed?
|
15
|
+
system("which pg_dump") == true
|
16
|
+
end
|
17
|
+
|
18
|
+
def import_installed?
|
19
|
+
system("which pg_restore") == true
|
20
|
+
end
|
21
|
+
|
22
|
+
def configure(opts)
|
23
|
+
super(opts)
|
24
|
+
if @all_databases
|
25
|
+
raise BadConfig.new "#{self.class} does not support --all-databases"
|
26
|
+
elsif @databases
|
27
|
+
raise BadConfig.new "#{self.class} does not support multiple --databases"
|
28
|
+
elsif @database
|
29
|
+
# supported
|
30
|
+
else
|
31
|
+
raise BadConfig.new "#{self.class} requires option --database"
|
32
|
+
end
|
33
|
+
if @tables
|
34
|
+
raise BadConfig.new "#{self.class} does not support --tables"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def dump_cmd
|
39
|
+
if @all_databases
|
40
|
+
"pg_dump -h #{host} -p #{port} -U #{user} --password #{password} #{dump_options}"
|
41
|
+
elsif @databases
|
42
|
+
# not supported
|
43
|
+
else
|
44
|
+
"pg_dump -h #{host} -p #{port} -U #{user} --password #{password} #{dump_options} #{database}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def import_cmd
|
49
|
+
if @database
|
50
|
+
"pg_restore -h #{host} -p #{port} -U #{user} --password #{password} --verbose --clean --no-owner --no-acl -d #{database} #{dumpfile}"
|
51
|
+
else
|
52
|
+
"pg_restore -h #{host} -p #{port} -U #{user} --password #{password} --verbose --clean --no-owner --no-acl #{database} #{dumpfile}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/dumpr/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dumpr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Dickson
|
@@ -10,12 +10,14 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Dumpr provides an easy way to dump and import databases.
|
13
|
+
description: Dumpr provides an easy way to dump and import databases. Supported databases
|
14
|
+
include MySQL and Postgres.
|
14
15
|
email:
|
15
16
|
- jdickson@bcap.com
|
16
17
|
executables:
|
17
18
|
- csv2sqlinsert
|
18
19
|
- dumpr
|
20
|
+
- dumpr-import
|
19
21
|
extensions: []
|
20
22
|
extra_rdoc_files:
|
21
23
|
- README.md
|
@@ -27,15 +29,17 @@ files:
|
|
27
29
|
- Rakefile
|
28
30
|
- bin/csv2sqlinsert
|
29
31
|
- bin/dumpr
|
32
|
+
- bin/dumpr-import
|
30
33
|
- dumpr.gemspec
|
31
34
|
- lib/dumpr.rb
|
32
35
|
- lib/dumpr/chunkpipe.rb
|
33
36
|
- lib/dumpr/cli.rb
|
34
37
|
- lib/dumpr/driver.rb
|
35
38
|
- lib/dumpr/driver/mysql.rb
|
39
|
+
- lib/dumpr/driver/postgres.rb
|
36
40
|
- lib/dumpr/util.rb
|
37
41
|
- lib/dumpr/version.rb
|
38
|
-
homepage: http://github.com/
|
42
|
+
homepage: http://github.com/jamesdickson6/dumpr
|
39
43
|
licenses:
|
40
44
|
- MIT
|
41
45
|
metadata: {}
|
@@ -55,8 +59,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
59
|
version: '0'
|
56
60
|
requirements: []
|
57
61
|
rubyforge_project:
|
58
|
-
rubygems_version: 2.
|
62
|
+
rubygems_version: 2.4.6
|
59
63
|
signing_key:
|
60
64
|
specification_version: 4
|
61
|
-
summary: Dump and
|
65
|
+
summary: Dump and import databases.
|
62
66
|
test_files: []
|