pg_export 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +9 -13
- data/.travis.yml +2 -2
- data/CHANGELOG.md +9 -0
- data/Gemfile +2 -0
- data/README.md +28 -29
- data/Rakefile +2 -0
- data/bin/console +2 -8
- data/bin/pg_export +44 -45
- data/lib/pg_export/build_logger.rb +4 -2
- data/lib/pg_export/configuration.rb +22 -2
- data/lib/pg_export/container.rb +48 -0
- data/lib/pg_export/import.rb +7 -0
- data/lib/pg_export/lib/pg_export/adapters/bash_adapter.rb +37 -0
- data/lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb +67 -0
- data/lib/pg_export/lib/pg_export/entities/dump.rb +45 -0
- data/lib/pg_export/lib/pg_export/factories/cipher_factory.rb +32 -0
- data/lib/pg_export/lib/pg_export/factories/dump_factory.rb +31 -0
- data/lib/pg_export/lib/pg_export/factories/ftp_adapter_factory.rb +22 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/build_dump.rb +19 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/close_ftp_connection.rb +19 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/decrypt_dump.rb +19 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/download_dump_from_ftp.rb +19 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/encrypt_dump.rb +19 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/fetch_dumps_from_ftp.rb +19 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/open_ftp_connection.rb +19 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/remove_old_dumps_from_ftp.rb +23 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/restore.rb +19 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/upload_dump_to_ftp.rb +19 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive_listener.rb +49 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/build_dump.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/close_ftp_connection.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/decrypt_dump.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/download_dump_from_ftp.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/encrypt_dump.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/fetch_dumps_from_ftp.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/open_ftp_connection.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/remove_old_dumps_from_ftp.rb +17 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/restore.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/upload_dump_to_ftp.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain_listener.rb +17 -0
- data/lib/pg_export/lib/pg_export/operations/decrypt_dump.rb +20 -0
- data/lib/pg_export/lib/pg_export/operations/encrypt_dump.rb +18 -0
- data/lib/pg_export/lib/pg_export/operations/open_ftp_connection.rb +19 -0
- data/lib/pg_export/lib/pg_export/operations/remove_old_dumps_from_ftp.rb +22 -0
- data/lib/pg_export/lib/pg_export/repositories/ftp_dump_file_repository.rb +19 -0
- data/lib/pg_export/lib/pg_export/repositories/ftp_dump_repository.rb +36 -0
- data/lib/pg_export/lib/pg_export/transactions/export_dump.rb +56 -0
- data/lib/pg_export/lib/pg_export/transactions/import_dump_interactively.rb +67 -0
- data/lib/pg_export/lib/pg_export/types.rb +14 -0
- data/lib/pg_export/lib/pg_export/ui/interactive/input.rb +36 -0
- data/lib/pg_export/lib/pg_export/ui/plain/input.rb +17 -0
- data/lib/pg_export/lib/pg_export/value_objects/dump_file.rb +70 -0
- data/lib/pg_export/system/boot/config.rb +11 -0
- data/lib/pg_export/system/boot/interactive.rb +32 -0
- data/lib/pg_export/system/boot/logger.rb +15 -0
- data/lib/pg_export/system/boot/plain.rb +33 -0
- data/lib/pg_export/version.rb +3 -1
- data/lib/pg_export.rb +23 -20
- data/pg_export.gemspec +13 -10
- metadata +108 -52
- data/lib/pg_export/aes/base.rb +0 -47
- data/lib/pg_export/aes/decryptor.rb +0 -13
- data/lib/pg_export/aes/encryptor.rb +0 -13
- data/lib/pg_export/aes.rb +0 -3
- data/lib/pg_export/bash/adapter.rb +0 -31
- data/lib/pg_export/bash/factory.rb +0 -23
- data/lib/pg_export/bash/repository.rb +0 -18
- data/lib/pg_export/boot_container.rb +0 -69
- data/lib/pg_export/dump.rb +0 -62
- data/lib/pg_export/errors.rb +0 -5
- data/lib/pg_export/ftp/adapter.rb +0 -41
- data/lib/pg_export/ftp/connection.rb +0 -40
- data/lib/pg_export/ftp/repository.rb +0 -40
- data/lib/pg_export/roles/colourable_string.rb +0 -19
- data/lib/pg_export/roles/human_readable.rb +0 -17
- data/lib/pg_export/roles/interactive.rb +0 -98
- data/lib/pg_export/roles/validatable.rb +0 -24
- data/lib/pg_export/services/create_and_export_dump.rb +0 -20
metadata
CHANGED
@@ -1,141 +1,169 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_export
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krzysztof Maicher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: dry-initializer
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.5.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: dry-
|
28
|
+
name: dry-system
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.10.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.10.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: dry-
|
42
|
+
name: dry-transaction
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.13.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.13.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tty-prompt
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tty-spinner
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: bundler
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
87
|
- - "~>"
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
89
|
+
version: '1.16'
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
94
|
- - "~>"
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
96
|
+
version: '1.16'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
98
|
+
name: pg
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - "~>"
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
103
|
+
version: '0.21'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
110
|
+
version: '0.21'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
112
|
+
name: pry
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
|
-
- - "
|
115
|
+
- - ">="
|
88
116
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
117
|
+
version: '0'
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
|
-
- - "
|
122
|
+
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
124
|
+
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
126
|
+
name: rake
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
129
|
- - "~>"
|
102
130
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
131
|
+
version: '10.0'
|
104
132
|
type: :development
|
105
133
|
prerelease: false
|
106
134
|
version_requirements: !ruby/object:Gem::Requirement
|
107
135
|
requirements:
|
108
136
|
- - "~>"
|
109
137
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
138
|
+
version: '10.0'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
140
|
+
name: rspec
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
114
142
|
requirements:
|
115
143
|
- - "~>"
|
116
144
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
145
|
+
version: '3.4'
|
118
146
|
type: :development
|
119
147
|
prerelease: false
|
120
148
|
version_requirements: !ruby/object:Gem::Requirement
|
121
149
|
requirements:
|
122
150
|
- - "~>"
|
123
151
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
152
|
+
version: '3.4'
|
125
153
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
154
|
+
name: rubocop
|
127
155
|
requirement: !ruby/object:Gem::Requirement
|
128
156
|
requirements:
|
129
|
-
- - "
|
157
|
+
- - "~>"
|
130
158
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
159
|
+
version: 0.59.2
|
132
160
|
type: :development
|
133
161
|
prerelease: false
|
134
162
|
version_requirements: !ruby/object:Gem::Requirement
|
135
163
|
requirements:
|
136
|
-
- - "
|
164
|
+
- - "~>"
|
137
165
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
166
|
+
version: 0.59.2
|
139
167
|
description: CLI for creating and exporting PostgreSQL dumps to FTP. Can
|
140
168
|
be used for backups or synchronizing databases between production and development
|
141
169
|
environments.
|
@@ -161,26 +189,54 @@ files:
|
|
161
189
|
- bin/pg_export
|
162
190
|
- bin/setup
|
163
191
|
- lib/pg_export.rb
|
164
|
-
- lib/pg_export/aes.rb
|
165
|
-
- lib/pg_export/aes/base.rb
|
166
|
-
- lib/pg_export/aes/decryptor.rb
|
167
|
-
- lib/pg_export/aes/encryptor.rb
|
168
|
-
- lib/pg_export/bash/adapter.rb
|
169
|
-
- lib/pg_export/bash/factory.rb
|
170
|
-
- lib/pg_export/bash/repository.rb
|
171
|
-
- lib/pg_export/boot_container.rb
|
172
192
|
- lib/pg_export/build_logger.rb
|
173
193
|
- lib/pg_export/configuration.rb
|
174
|
-
- lib/pg_export/
|
175
|
-
- lib/pg_export/
|
176
|
-
- lib/pg_export/
|
177
|
-
- lib/pg_export/
|
178
|
-
- lib/pg_export/
|
179
|
-
- lib/pg_export/
|
180
|
-
- lib/pg_export/
|
181
|
-
- lib/pg_export/
|
182
|
-
- lib/pg_export/
|
183
|
-
- lib/pg_export/
|
194
|
+
- lib/pg_export/container.rb
|
195
|
+
- lib/pg_export/import.rb
|
196
|
+
- lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
|
197
|
+
- lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb
|
198
|
+
- lib/pg_export/lib/pg_export/entities/dump.rb
|
199
|
+
- lib/pg_export/lib/pg_export/factories/cipher_factory.rb
|
200
|
+
- lib/pg_export/lib/pg_export/factories/dump_factory.rb
|
201
|
+
- lib/pg_export/lib/pg_export/factories/ftp_adapter_factory.rb
|
202
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/build_dump.rb
|
203
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/close_ftp_connection.rb
|
204
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/decrypt_dump.rb
|
205
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/download_dump_from_ftp.rb
|
206
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/encrypt_dump.rb
|
207
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/fetch_dumps_from_ftp.rb
|
208
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/open_ftp_connection.rb
|
209
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/remove_old_dumps_from_ftp.rb
|
210
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/restore.rb
|
211
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/upload_dump_to_ftp.rb
|
212
|
+
- lib/pg_export/lib/pg_export/listeners/interactive_listener.rb
|
213
|
+
- lib/pg_export/lib/pg_export/listeners/plain/build_dump.rb
|
214
|
+
- lib/pg_export/lib/pg_export/listeners/plain/close_ftp_connection.rb
|
215
|
+
- lib/pg_export/lib/pg_export/listeners/plain/decrypt_dump.rb
|
216
|
+
- lib/pg_export/lib/pg_export/listeners/plain/download_dump_from_ftp.rb
|
217
|
+
- lib/pg_export/lib/pg_export/listeners/plain/encrypt_dump.rb
|
218
|
+
- lib/pg_export/lib/pg_export/listeners/plain/fetch_dumps_from_ftp.rb
|
219
|
+
- lib/pg_export/lib/pg_export/listeners/plain/open_ftp_connection.rb
|
220
|
+
- lib/pg_export/lib/pg_export/listeners/plain/remove_old_dumps_from_ftp.rb
|
221
|
+
- lib/pg_export/lib/pg_export/listeners/plain/restore.rb
|
222
|
+
- lib/pg_export/lib/pg_export/listeners/plain/upload_dump_to_ftp.rb
|
223
|
+
- lib/pg_export/lib/pg_export/listeners/plain_listener.rb
|
224
|
+
- lib/pg_export/lib/pg_export/operations/decrypt_dump.rb
|
225
|
+
- lib/pg_export/lib/pg_export/operations/encrypt_dump.rb
|
226
|
+
- lib/pg_export/lib/pg_export/operations/open_ftp_connection.rb
|
227
|
+
- lib/pg_export/lib/pg_export/operations/remove_old_dumps_from_ftp.rb
|
228
|
+
- lib/pg_export/lib/pg_export/repositories/ftp_dump_file_repository.rb
|
229
|
+
- lib/pg_export/lib/pg_export/repositories/ftp_dump_repository.rb
|
230
|
+
- lib/pg_export/lib/pg_export/transactions/export_dump.rb
|
231
|
+
- lib/pg_export/lib/pg_export/transactions/import_dump_interactively.rb
|
232
|
+
- lib/pg_export/lib/pg_export/types.rb
|
233
|
+
- lib/pg_export/lib/pg_export/ui/interactive/input.rb
|
234
|
+
- lib/pg_export/lib/pg_export/ui/plain/input.rb
|
235
|
+
- lib/pg_export/lib/pg_export/value_objects/dump_file.rb
|
236
|
+
- lib/pg_export/system/boot/config.rb
|
237
|
+
- lib/pg_export/system/boot/interactive.rb
|
238
|
+
- lib/pg_export/system/boot/logger.rb
|
239
|
+
- lib/pg_export/system/boot/plain.rb
|
184
240
|
- lib/pg_export/version.rb
|
185
241
|
- pg_export.gemspec
|
186
242
|
homepage: https://github.com/maicher/pg_export
|
@@ -195,7 +251,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
251
|
requirements:
|
196
252
|
- - ">="
|
197
253
|
- !ruby/object:Gem::Version
|
198
|
-
version: 2.
|
254
|
+
version: 2.3.0
|
199
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
256
|
requirements:
|
201
257
|
- - ">="
|
@@ -203,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
259
|
version: '0'
|
204
260
|
requirements: []
|
205
261
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.
|
262
|
+
rubygems_version: 2.7.3
|
207
263
|
signing_key:
|
208
264
|
specification_version: 4
|
209
265
|
summary: CLI for creating and exporting PostgreSQL dumps to FTP.
|
data/lib/pg_export/aes/base.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'openssl'
|
2
|
-
require 'pg_export/dump'
|
3
|
-
|
4
|
-
class PgExport
|
5
|
-
module Aes
|
6
|
-
class Base
|
7
|
-
ALGORITHM = 'AES-128-CBC'.freeze
|
8
|
-
|
9
|
-
def initialize(key:, logger:)
|
10
|
-
@key, @logger = key, logger
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(source_dump)
|
14
|
-
target_dump = Dump.new(name: target_dump_name, db_name: source_dump.db_name)
|
15
|
-
copy(from: source_dump, to: target_dump)
|
16
|
-
logger.info "Create #{target_dump}"
|
17
|
-
target_dump
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
attr_reader :key, :logger
|
23
|
-
|
24
|
-
def copy(from:, to:)
|
25
|
-
cipher.reset
|
26
|
-
to.open(:write) do |f|
|
27
|
-
from.each_chunk do |chunk|
|
28
|
-
f << cipher.update(chunk)
|
29
|
-
end
|
30
|
-
f << cipher.final
|
31
|
-
end
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
def cipher
|
36
|
-
@cipher ||= build_cipher
|
37
|
-
end
|
38
|
-
|
39
|
-
def build_cipher
|
40
|
-
OpenSSL::Cipher.new(ALGORITHM).tap do |cipher|
|
41
|
-
cipher.public_send(cipher_type)
|
42
|
-
cipher.key = key
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/pg_export/aes.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
require 'pg_export/errors'
|
3
|
-
|
4
|
-
class PgExport
|
5
|
-
module Bash
|
6
|
-
class Adapter
|
7
|
-
def get(path, db_name)
|
8
|
-
popen("pg_dump -Fc --file #{path} #{db_name}") do |errors|
|
9
|
-
raise PgDumpError, errors unless errors.empty?
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def persist(path, db_name)
|
14
|
-
popen("pg_restore -c -d #{db_name} #{path}") do |errors|
|
15
|
-
raise PgRestoreError, errors if /FATAL/ =~ errors
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def popen(command)
|
22
|
-
Open3.popen3(command) do |_, _, err|
|
23
|
-
errors = err.read
|
24
|
-
yield errors
|
25
|
-
end
|
26
|
-
|
27
|
-
self
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
require 'pg_export/dump'
|
3
|
-
|
4
|
-
class PgExport
|
5
|
-
module Bash
|
6
|
-
class Factory
|
7
|
-
def initialize(adapter:, logger:)
|
8
|
-
@adapter, @logger = adapter, logger
|
9
|
-
end
|
10
|
-
|
11
|
-
def build_dump(db_name)
|
12
|
-
dump = Dump.new(name: 'Dump', db_name: db_name)
|
13
|
-
adapter.get(dump.path, dump.db_name)
|
14
|
-
logger.info "Create #{dump}"
|
15
|
-
dump
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
attr_reader :adapter, :logger
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class PgExport
|
2
|
-
module Bash
|
3
|
-
class Repository
|
4
|
-
def initialize(adapter:, logger:)
|
5
|
-
@adapter, @logger = adapter, logger
|
6
|
-
end
|
7
|
-
|
8
|
-
def persist(dump, db_name)
|
9
|
-
adapter.persist(dump.path, db_name)
|
10
|
-
logger.info "Persist #{dump} #{db_name} to #{adapter}"
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
attr_reader :adapter, :logger
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require_relative 'build_logger'
|
2
|
-
require_relative 'ftp/adapter'
|
3
|
-
require_relative 'ftp/connection'
|
4
|
-
require_relative 'ftp/repository'
|
5
|
-
require_relative 'bash/adapter'
|
6
|
-
require_relative 'bash/repository'
|
7
|
-
require_relative 'bash/factory'
|
8
|
-
require_relative 'aes'
|
9
|
-
require_relative 'services/create_and_export_dump'
|
10
|
-
|
11
|
-
class PgExport
|
12
|
-
class BootContainer
|
13
|
-
class << self
|
14
|
-
def call(config)
|
15
|
-
container = {}
|
16
|
-
|
17
|
-
boot_logger(container, config)
|
18
|
-
boot_aes(container, config)
|
19
|
-
boot_ftp(container, config)
|
20
|
-
boot_bash(container)
|
21
|
-
boot_services(container)
|
22
|
-
|
23
|
-
container
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def boot_logger(container, config)
|
29
|
-
container[:logger] = BuildLogger.call(stream: $stdout, format: config[:logger_format])
|
30
|
-
end
|
31
|
-
|
32
|
-
def boot_aes(container, config)
|
33
|
-
container[:encryptor] = Aes::Encryptor.new(key: config[:dump_encryption_key], logger: container[:logger])
|
34
|
-
container[:decryptor] = Aes::Decryptor.new(key: config[:dump_encryption_key], logger: container[:logger])
|
35
|
-
end
|
36
|
-
|
37
|
-
def boot_ftp(container, config)
|
38
|
-
container[:ftp_connection] = Ftp::Connection.new(
|
39
|
-
host: config[:ftp_host],
|
40
|
-
user: config[:ftp_user],
|
41
|
-
password: config[:ftp_password],
|
42
|
-
logger: container[:logger]
|
43
|
-
)
|
44
|
-
container[:ftp_adapter] = Ftp::Adapter.new(connection: container[:ftp_connection])
|
45
|
-
container[:ftp_repository] = Ftp::Repository.new(adapter: container[:ftp_adapter], logger: container[:logger])
|
46
|
-
end
|
47
|
-
|
48
|
-
def boot_bash(container)
|
49
|
-
container[:bash_adapter] = Bash::Adapter.new
|
50
|
-
container[:bash_repository] = Bash::Repository.new(
|
51
|
-
adapter: container[:bash_adapter],
|
52
|
-
logger: container[:logger]
|
53
|
-
)
|
54
|
-
container[:bash_factory] = Bash::Factory.new(
|
55
|
-
adapter: container[:bash_adapter],
|
56
|
-
logger: container[:logger]
|
57
|
-
)
|
58
|
-
end
|
59
|
-
|
60
|
-
def boot_services(container)
|
61
|
-
container[:create_and_export_dump] = Services::CreateAndExportDump.new(
|
62
|
-
bash_factory: container[:bash_factory],
|
63
|
-
encryptor: container[:encryptor],
|
64
|
-
ftp_repository: container[:ftp_repository]
|
65
|
-
)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/lib/pg_export/dump.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
require 'tempfile'
|
3
|
-
|
4
|
-
require_relative 'roles/human_readable'
|
5
|
-
|
6
|
-
class PgExport
|
7
|
-
class Dump
|
8
|
-
TIMESTAMP = '_%Y%m%d_%H%M%S'.freeze
|
9
|
-
|
10
|
-
extend Forwardable
|
11
|
-
include Roles::HumanReadable
|
12
|
-
|
13
|
-
CHUNK_SIZE = (2**16).freeze
|
14
|
-
|
15
|
-
def_delegators :file, :path, :read, :write, :<<, :rewind, :close, :size, :eof?
|
16
|
-
|
17
|
-
attr_reader :name, :db_name
|
18
|
-
|
19
|
-
def initialize(name:, db_name:)
|
20
|
-
@name, @db_name = name, db_name
|
21
|
-
@timestamp = Time.now.strftime(TIMESTAMP)
|
22
|
-
end
|
23
|
-
|
24
|
-
def ext
|
25
|
-
''
|
26
|
-
end
|
27
|
-
|
28
|
-
def open(operation_type, &block)
|
29
|
-
case operation_type.to_sym
|
30
|
-
when :read then File.open(path, 'r', &block)
|
31
|
-
when :write then File.open(path, 'w', &block)
|
32
|
-
else raise ArgumentError, 'Operation type can be only :read or :write'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def each_chunk
|
37
|
-
open(:read) do |file|
|
38
|
-
yield file.read(CHUNK_SIZE) until file.eof?
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def timestamped_name
|
43
|
-
db_name + timestamp + ext
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_s
|
47
|
-
"#{name} (#{size_human})"
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
attr_reader :timestamp
|
53
|
-
|
54
|
-
def file
|
55
|
-
@file ||= Tempfile.new(file_name)
|
56
|
-
end
|
57
|
-
|
58
|
-
def file_name
|
59
|
-
name.downcase.gsub(/[^0-9a-z]/, '_')
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/lib/pg_export/errors.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
class PgExport
|
2
|
-
module Ftp
|
3
|
-
class Adapter
|
4
|
-
CHUNK_SIZE = (2**16).freeze
|
5
|
-
|
6
|
-
def initialize(connection:)
|
7
|
-
@connection = connection
|
8
|
-
@host = connection.host
|
9
|
-
ObjectSpace.define_finalizer(self, proc { connection.close })
|
10
|
-
end
|
11
|
-
|
12
|
-
def list(regex_string)
|
13
|
-
ftp.list(regex_string).map { |item| item.split(' ').last }.sort.reverse
|
14
|
-
end
|
15
|
-
|
16
|
-
def delete(filename)
|
17
|
-
ftp.delete(filename)
|
18
|
-
end
|
19
|
-
|
20
|
-
def persist(path, timestamped_name)
|
21
|
-
ftp.putbinaryfile(path, timestamped_name, CHUNK_SIZE)
|
22
|
-
end
|
23
|
-
|
24
|
-
def get(path, timestamped_name)
|
25
|
-
ftp.getbinaryfile(timestamped_name, path, CHUNK_SIZE)
|
26
|
-
end
|
27
|
-
|
28
|
-
def ftp
|
29
|
-
connection.ftp
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_s
|
33
|
-
host
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
attr_reader :connection, :host
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'net/ftp'
|
2
|
-
|
3
|
-
class PgExport
|
4
|
-
module Ftp
|
5
|
-
class Connection
|
6
|
-
attr_reader :host
|
7
|
-
|
8
|
-
def initialize(host:, user:, password:, logger:)
|
9
|
-
@host, @user, @password, @logger = host, user, password, logger
|
10
|
-
open_ftp_thread
|
11
|
-
end
|
12
|
-
|
13
|
-
def ftp
|
14
|
-
open_ftp_thread.join
|
15
|
-
@ftp
|
16
|
-
end
|
17
|
-
|
18
|
-
def close
|
19
|
-
ftp.close
|
20
|
-
logger.info 'Close FTP'
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
attr_reader :user, :password, :logger
|
27
|
-
|
28
|
-
def open
|
29
|
-
@ftp = Net::FTP.new(host, user, password)
|
30
|
-
@ftp.passive = true
|
31
|
-
logger.info "Connect to #{host}"
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
def open_ftp_thread
|
36
|
-
@open_ftp_thread ||= Thread.new { open }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|