pg_export 0.7.7 → 1.0.0.rc1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +6 -3
- data/CHANGELOG.md +9 -0
- data/README.md +13 -10
- data/bin/pg_export +20 -7
- data/lib/pg_export/configuration.rb +11 -7
- data/lib/pg_export/container.rb +17 -8
- data/lib/pg_export/import.rb +1 -1
- data/lib/pg_export/lib/pg_export/factories/ftp_gateway_factory.rb +22 -0
- data/lib/pg_export/lib/pg_export/factories/ssh_gateway_factory.rb +22 -0
- data/lib/pg_export/lib/pg_export/{adapters/ftp_adapter.rb → gateways/ftp.rb} +9 -6
- data/lib/pg_export/lib/pg_export/gateways/ssh.rb +74 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/build_dump.rb +4 -4
- data/lib/pg_export/lib/pg_export/listeners/interactive/{close_ftp_connection.rb → close_connection.rb} +1 -1
- data/lib/pg_export/lib/pg_export/listeners/interactive/decrypt_dump.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/interactive/download_dump_from_ftp.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/interactive/encrypt_dump.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/interactive/{open_ftp_connection.rb → open_connection.rb} +1 -1
- data/lib/pg_export/lib/pg_export/listeners/interactive/remove_old_dumps_from_ftp.rb +5 -5
- data/lib/pg_export/lib/pg_export/listeners/interactive/restore.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/interactive/upload_dump_to_ftp.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/interactive_listener.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/build_dump.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/{close_ftp_connection.rb → close_connection.rb} +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/decrypt_dump.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/download_dump_from_ftp.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/encrypt_dump.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/fetch_dumps_from_ftp.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/open_connection.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/remove_old_dumps_from_ftp.rb +3 -3
- data/lib/pg_export/lib/pg_export/listeners/plain/restore.rb +1 -1
- data/lib/pg_export/lib/pg_export/listeners/plain/upload_dump_to_ftp.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain_listener.rb +2 -2
- data/lib/pg_export/lib/pg_export/operations/{open_ftp_connection.rb → open_connection.rb} +5 -5
- data/lib/pg_export/lib/pg_export/operations/remove_old_dumps_from_ftp.rb +6 -6
- data/lib/pg_export/lib/pg_export/repositories/{ftp_dump_file_repository.rb → gateway_dump_file_repository.rb} +3 -3
- data/lib/pg_export/lib/pg_export/repositories/{ftp_dump_repository.rb → gateway_dump_repository.rb} +7 -7
- data/lib/pg_export/lib/pg_export/transactions/export_dump.rb +8 -8
- data/lib/pg_export/lib/pg_export/transactions/import_dump_interactively.rb +14 -14
- data/lib/pg_export/system/boot/interactive.rb +1 -1
- data/lib/pg_export/system/boot/plain.rb +2 -2
- data/lib/pg_export/version.rb +1 -1
- data/pg_export.gemspec +4 -2
- metadata +48 -18
- data/lib/pg_export/lib/pg_export/factories/ftp_adapter_factory.rb +0 -22
- data/lib/pg_export/lib/pg_export/listeners/plain/open_ftp_connection.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3eb793296ca1e2e22519a8abf1644f88fd06daa02a672d392f318a19128c50cb
|
|
4
|
+
data.tar.gz: '085a37ec1e0b7cc96f811e73a0a3271086e1c12fba3e6a2da831c6f58a4f9fde'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a3b89d600dc035cca7cdc909b503ac1d62e7844531d5f8a35c8213339968074ccb21d49669a1623f3d616f0aa52c2ccfb1c6c0a54f864e602ffcbe32a43c0886
|
|
7
|
+
data.tar.gz: 9a93edd9855a3a20d5745491cedbcff104cd8aee180e1c10537c63c129c8ed96933f36d5120476b85812aece2bcaba507391910e282097b5a8555e210a0e209e
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
sudo: false
|
|
2
1
|
language: ruby
|
|
3
2
|
rvm:
|
|
4
|
-
-
|
|
3
|
+
- 3.0.0
|
|
4
|
+
- 2.7.2
|
|
5
|
+
- 2.4.10
|
|
6
|
+
services:
|
|
7
|
+
- postgresql
|
|
5
8
|
addons:
|
|
6
9
|
code_climate:
|
|
7
10
|
repo_token: db03e5968c5bcd68b12ca50f5d41ae07dd74fe80d4e1421d754e31c316e7477a
|
|
8
|
-
before_install: gem install bundler -v
|
|
11
|
+
before_install: gem install bundler -v 2.2.3
|
|
9
12
|
after_success: codeclimate-test-reporter
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
### 1.0.0 - 2021.03.20
|
|
2
|
+
- Make it compatible with Ruby 3.0
|
|
3
|
+
- Change configuration envs:
|
|
4
|
+
- BACKUP_FTP_HOST -> PG_EXPORT_GATEWAY_HOST
|
|
5
|
+
- BACKUP_FTP_USER -> PG_EXPORT_GATEWAY_USER
|
|
6
|
+
- BACKUP_FTP_PASSWORD -> PG_EXPORT_GATEWAY_PASSWORD
|
|
7
|
+
- DUMP_ENCRYPTION_KEY -> PG_EXPORT_ENCRYPTION_KEY
|
|
8
|
+
- Drop Ruby 2.3 support
|
|
9
|
+
|
|
1
10
|
### 0.7.7 - 2020.09.07
|
|
2
11
|
|
|
3
12
|
- Upgrade dry-initializer
|
data/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Features:
|
|
|
26
26
|
|
|
27
27
|
## Dependencies
|
|
28
28
|
|
|
29
|
-
* Ruby >= 2.3.0
|
|
29
|
+
* Ruby >= 2.4 (works with Ruby 3.0)
|
|
30
30
|
* $ pg_dump
|
|
31
31
|
* $ pg_restore
|
|
32
32
|
|
|
@@ -51,29 +51,32 @@ Or install it yourself as:
|
|
|
51
51
|
$ pg_export -h
|
|
52
52
|
|
|
53
53
|
Usage: pg_export [options]
|
|
54
|
+
-g, --gateway GATEWAY [Optional] ssh or ftp (default: ftp)
|
|
54
55
|
-d, --database DATABASE [Required] Name of the database to export
|
|
55
56
|
-k, --keep [KEEP] [Optional] Number of dump files to keep on FTP (default: 10)
|
|
56
57
|
-t, --timestamped [Optional] Enables log messages with timestamps
|
|
57
58
|
-m, --muted [Optional] Mutes log messages (overrides -t option)
|
|
58
59
|
-i, --interactive [Optional] Interactive command line mode - for restoring dumps into databases
|
|
60
|
+
-v, --version Show version
|
|
59
61
|
-h, --help Show this message
|
|
60
|
-
|
|
62
|
+
|
|
61
63
|
Setting can be verified by running following commands:
|
|
62
64
|
-c, --configuration Prints the configuration
|
|
63
|
-
-
|
|
65
|
+
-w, --welcome Tries connecting to the gateway (FTP or SSH) to verify the connection
|
|
66
|
+
|
|
64
67
|
|
|
65
68
|
## How to start
|
|
66
69
|
|
|
67
70
|
__Step 1.__ Prepare ENV variables.
|
|
68
71
|
|
|
69
72
|
/* FTP storage for database dumps. */
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
PG_EXPORT_GATEWAY_HOST=yourftp.example.com
|
|
74
|
+
PG_EXPORT_GATEWAY_USER=user
|
|
75
|
+
PG_EXPORT_GATEWAY_PASSWORD=password
|
|
73
76
|
|
|
74
77
|
/* Encryption key shoul have exactly 16 characters. */
|
|
75
78
|
/* Dumps will be SSL(AES-128-CBC) encrypted using this key. */
|
|
76
|
-
|
|
79
|
+
PG_EXPORT_ENCRYPTION_KEY=1234567890abcdef
|
|
77
80
|
|
|
78
81
|
/* Dumps to be kept on FTP */
|
|
79
82
|
/* Optional, defaults to 10 */
|
|
@@ -84,12 +87,12 @@ Note, that variables cannot include `#` sign, [more info](http://serverfault.com
|
|
|
84
87
|
__Step 2.__ Print the configuration to verify if env variables has been loaded properly.
|
|
85
88
|
|
|
86
89
|
$ pg_export --configuration
|
|
87
|
-
=> {:dump_encryption_key=>"k4***", :
|
|
88
|
-
:
|
|
90
|
+
=> {:dump_encryption_key=>"k4***", :gateway_host=>"yourftp.example.com", :gateway_user=>"your_gateway_user",
|
|
91
|
+
:gateway_password=>"pass***", :logger_format=>"plain", :keep_dumps=>2}
|
|
89
92
|
|
|
90
93
|
__Step 3.__ Try connecting to FTP to verify the connection.
|
|
91
94
|
|
|
92
|
-
$ pg_export --ftp
|
|
95
|
+
$ pg_export --gateway ftp --welcome
|
|
93
96
|
=> 230 User your_ftp_user logged in
|
|
94
97
|
|
|
95
98
|
__Step 4.__ Perform database export.
|
data/bin/pg_export
CHANGED
|
@@ -4,15 +4,20 @@
|
|
|
4
4
|
require 'optparse'
|
|
5
5
|
|
|
6
6
|
require 'pg_export'
|
|
7
|
-
require 'pg_export/container'
|
|
8
7
|
|
|
9
8
|
ENV['KEEP_DUMPS'] = ENV['KEEP_DUMPS'] || '10'
|
|
9
|
+
ENV['GATEWAY'] = 'ftp'
|
|
10
|
+
|
|
10
11
|
interactive = false
|
|
11
12
|
database = nil
|
|
12
13
|
|
|
13
14
|
option_parser = OptionParser.new do |opts|
|
|
14
15
|
opts.banner = 'Usage: pg_export [options]'
|
|
15
16
|
|
|
17
|
+
opts.on('-g', '--gateway GATEWAY', String, '[Optional] ssh or ftp (default: ftp)') do |g|
|
|
18
|
+
ENV['GATEWAY'] = g
|
|
19
|
+
end
|
|
20
|
+
|
|
16
21
|
opts.on('-d', '--database DATABASE', String, '[Required] Name of the database to export') do |d|
|
|
17
22
|
database = d
|
|
18
23
|
end
|
|
@@ -33,6 +38,11 @@ option_parser = OptionParser.new do |opts|
|
|
|
33
38
|
interactive = true
|
|
34
39
|
end
|
|
35
40
|
|
|
41
|
+
opts.on('-v', '--version', 'Show version') do
|
|
42
|
+
puts PgExport::VERSION
|
|
43
|
+
exit
|
|
44
|
+
end
|
|
45
|
+
|
|
36
46
|
opts.on('-h', '--help', 'Show this message') do
|
|
37
47
|
puts opts
|
|
38
48
|
exit
|
|
@@ -41,16 +51,17 @@ option_parser = OptionParser.new do |opts|
|
|
|
41
51
|
opts.separator "\nSetting can be verified by running following commands:"
|
|
42
52
|
|
|
43
53
|
opts.on('-c', '--configuration', 'Prints the configuration') do
|
|
54
|
+
require 'pg_export/container'
|
|
44
55
|
PgExport::Container.start(:config)
|
|
45
56
|
puts PgExport::Container['config'].to_h
|
|
46
57
|
exit
|
|
47
58
|
end
|
|
48
59
|
|
|
49
|
-
opts.on('-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
puts
|
|
60
|
+
opts.on('-w', '--welcome', 'Tries connecting to the gateway (FTP or SSH) to verify the connection') do
|
|
61
|
+
require 'pg_export/container'
|
|
62
|
+
PgExport::Container.start(ENV['GATEWAY'].to_sym)
|
|
63
|
+
gateway = PgExport::Container['factories.gateway_factory'].gateway
|
|
64
|
+
puts gateway.welcome
|
|
54
65
|
exit
|
|
55
66
|
end
|
|
56
67
|
end
|
|
@@ -63,6 +74,8 @@ rescue OptionParser::ParseError => e
|
|
|
63
74
|
exit
|
|
64
75
|
end
|
|
65
76
|
|
|
77
|
+
require 'pg_export/container'
|
|
78
|
+
|
|
66
79
|
begin
|
|
67
80
|
pg_export =
|
|
68
81
|
if interactive
|
|
@@ -78,5 +91,5 @@ end
|
|
|
78
91
|
|
|
79
92
|
pg_export.call(database) do |result|
|
|
80
93
|
result.success { puts 'Success' }
|
|
81
|
-
result.failure { |
|
|
94
|
+
result.failure { |outcome| warn outcome[:message] }
|
|
82
95
|
end
|
|
@@ -8,18 +8,18 @@ class PgExport
|
|
|
8
8
|
include Dry::Types()
|
|
9
9
|
|
|
10
10
|
attribute :dump_encryption_key, Strict::String.constrained(size: 16)
|
|
11
|
-
attribute :
|
|
12
|
-
attribute :
|
|
13
|
-
attribute :
|
|
11
|
+
attribute :gateway_host, Strict::String
|
|
12
|
+
attribute :gateway_user, Strict::String
|
|
13
|
+
attribute :gateway_password, Strict::String.optional
|
|
14
14
|
attribute :logger_format, Coercible::String.enum('plain', 'timestamped', 'muted')
|
|
15
15
|
attribute :keep_dumps, Coercible::Integer.constrained(gteq: 0)
|
|
16
16
|
|
|
17
17
|
def self.build(env)
|
|
18
18
|
new(
|
|
19
|
-
dump_encryption_key: env['
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
dump_encryption_key: env['PG_EXPORT_ENCRYPTION_KEY'],
|
|
20
|
+
gateway_host: env['PG_EXPORT_GATEWAY_HOST'],
|
|
21
|
+
gateway_user: env['PG_EXPORT_GATEWAY_USER'],
|
|
22
|
+
gateway_password: env['PG_EXPORT_GATEWAY_PASSWORD'] == '' ? nil : env['PG_EXPORT_GATEWAY_PASSWORD'],
|
|
23
23
|
logger_format: env['LOGGER_FORMAT'] || 'plain',
|
|
24
24
|
keep_dumps: env['KEEP_DUMPS'] || 10
|
|
25
25
|
)
|
|
@@ -27,6 +27,10 @@ class PgExport
|
|
|
27
27
|
raise PgExport::InitializationError, e.message.gsub('[PgExport::Configuration.new] ', '')
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
def gateway
|
|
31
|
+
ENV['GATEWAY'].to_sym
|
|
32
|
+
end
|
|
33
|
+
|
|
30
34
|
def logger_muted?
|
|
31
35
|
logger_format == 'muted'
|
|
32
36
|
end
|
data/lib/pg_export/container.rb
CHANGED
|
@@ -16,32 +16,41 @@ class PgExport
|
|
|
16
16
|
|
|
17
17
|
boot(:ftp) do
|
|
18
18
|
init do
|
|
19
|
-
require 'pg_export/lib/pg_export/factories/
|
|
19
|
+
require 'pg_export/lib/pg_export/factories/ftp_gateway_factory'
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
start do
|
|
23
23
|
use :config
|
|
24
|
+
register('factories.gateway_factory') { ::PgExport::Factories::FtpGatewayFactory.new }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
boot(:ssh) do
|
|
29
|
+
init do
|
|
30
|
+
require 'pg_export/lib/pg_export/factories/ssh_gateway_factory'
|
|
31
|
+
end
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
start do
|
|
34
|
+
use :config
|
|
35
|
+
register('factories.gateway_factory') { ::PgExport::Factories::SshGatewayFactory.new }
|
|
28
36
|
end
|
|
29
37
|
end
|
|
30
38
|
|
|
31
|
-
boot(:main) do
|
|
39
|
+
boot(:main) do |system|
|
|
32
40
|
init do
|
|
33
41
|
require 'pg_export/lib/pg_export/operations/encrypt_dump'
|
|
34
42
|
require 'pg_export/lib/pg_export/operations/decrypt_dump'
|
|
35
43
|
require 'pg_export/lib/pg_export/operations/remove_old_dumps_from_ftp'
|
|
36
|
-
require 'pg_export/lib/pg_export/operations/
|
|
44
|
+
require 'pg_export/lib/pg_export/operations/open_connection'
|
|
37
45
|
end
|
|
38
46
|
|
|
39
47
|
start do
|
|
40
|
-
use
|
|
48
|
+
use(system[:config].gateway)
|
|
49
|
+
|
|
41
50
|
register('operations.encrypt_dump') { ::PgExport::Operations::EncryptDump.new }
|
|
42
51
|
register('operations.decrypt_dump') { ::PgExport::Operations::DecryptDump.new }
|
|
43
52
|
register('operations.remove_old_dumps_from_ftp') { ::PgExport::Operations::RemoveOldDumpsFromFtp.new }
|
|
44
|
-
register('operations.
|
|
53
|
+
register('operations.open_connection') { ::PgExport::Operations::OpenConnection.new }
|
|
45
54
|
end
|
|
46
55
|
end
|
|
47
56
|
end
|
data/lib/pg_export/import.rb
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# auto_register: false
|
|
4
|
+
|
|
5
|
+
require 'pg_export/lib/pg_export/gateways/ftp'
|
|
6
|
+
require 'pg_export/import'
|
|
7
|
+
|
|
8
|
+
class PgExport
|
|
9
|
+
module Factories
|
|
10
|
+
class FtpGatewayFactory
|
|
11
|
+
include Import['config']
|
|
12
|
+
|
|
13
|
+
def gateway
|
|
14
|
+
::PgExport::Gateways::Ftp.new(
|
|
15
|
+
host: config.gateway_host,
|
|
16
|
+
user: config.gateway_user,
|
|
17
|
+
password: config.gateway_password
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# auto_register: false
|
|
4
|
+
|
|
5
|
+
require 'pg_export/lib/pg_export/gateways/ssh'
|
|
6
|
+
require 'pg_export/import'
|
|
7
|
+
|
|
8
|
+
class PgExport
|
|
9
|
+
module Factories
|
|
10
|
+
class SshGatewayFactory
|
|
11
|
+
include Import['config']
|
|
12
|
+
|
|
13
|
+
def gateway
|
|
14
|
+
::PgExport::Gateways::Ssh.new(
|
|
15
|
+
host: config.gateway_host,
|
|
16
|
+
user: config.gateway_user,
|
|
17
|
+
password: config.gateway_password
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -5,22 +5,25 @@
|
|
|
5
5
|
require 'net/ftp'
|
|
6
6
|
|
|
7
7
|
class PgExport
|
|
8
|
-
module
|
|
9
|
-
class
|
|
8
|
+
module Gateways
|
|
9
|
+
class Ftp
|
|
10
10
|
CHUNK_SIZE = (2**16).freeze
|
|
11
11
|
|
|
12
12
|
def initialize(host:, user:, password:)
|
|
13
13
|
@host, @user, @password, @logger = host, user, password
|
|
14
|
-
ObjectSpace.define_finalizer(self, proc { ftp.close if @ftp })
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
def
|
|
16
|
+
def open
|
|
18
17
|
@ftp = Net::FTP.new(host, user, password)
|
|
19
18
|
@ftp.passive = true
|
|
20
19
|
@ftp
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
def
|
|
22
|
+
def welcome
|
|
23
|
+
open.welcome
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def close
|
|
24
27
|
@ftp&.close
|
|
25
28
|
end
|
|
26
29
|
|
|
@@ -49,7 +52,7 @@ class PgExport
|
|
|
49
52
|
end
|
|
50
53
|
|
|
51
54
|
def ftp
|
|
52
|
-
@ftp ||=
|
|
55
|
+
@ftp ||= open
|
|
53
56
|
end
|
|
54
57
|
|
|
55
58
|
private
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# auto_register: false
|
|
4
|
+
|
|
5
|
+
require 'net/ssh'
|
|
6
|
+
require 'net/scp'
|
|
7
|
+
|
|
8
|
+
class PgExport
|
|
9
|
+
module Gateways
|
|
10
|
+
class Ssh
|
|
11
|
+
CHUNK_SIZE = (2**16).freeze
|
|
12
|
+
|
|
13
|
+
def initialize(host:, user:, password:)
|
|
14
|
+
@host, @user, @password, @logger = host, user, password
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def open
|
|
18
|
+
if password.nil?
|
|
19
|
+
@ssh = Net::SSH.start(host, user)
|
|
20
|
+
else
|
|
21
|
+
@ssh = Net::SSH.start(host, user, password)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def welcome
|
|
26
|
+
open.exec!('hostname')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def close
|
|
30
|
+
@ssh&.close
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def list(regex_string)
|
|
34
|
+
ssh
|
|
35
|
+
.exec!("ls -l | grep #{regex_string.gsub('*', '')}")
|
|
36
|
+
.split("\n")
|
|
37
|
+
.map { |row| extract_meaningful_attributes(row) }
|
|
38
|
+
.sort_by { |item| item[:name] }
|
|
39
|
+
.reverse
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def delete(name)
|
|
43
|
+
# @TODO
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def persist(file, name)
|
|
47
|
+
ssh.scp.upload(file.path, name).wait
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def get(file, name)
|
|
51
|
+
ssh.scp.download(name, file.path).wait
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def to_s
|
|
55
|
+
host
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def ssh
|
|
59
|
+
@ssh ||= open
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
attr_reader :host, :user, :password
|
|
65
|
+
|
|
66
|
+
def extract_meaningful_attributes(item)
|
|
67
|
+
MEANINGFUL_KEYS.zip(item.split(' ').values_at(8, 4)).to_h
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
MEANINGFUL_KEYS = %i[name size].freeze
|
|
71
|
+
private_constant :MEANINGFUL_KEYS
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -6,12 +6,12 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Interactive
|
|
8
8
|
class BuildDump < InteractiveListener
|
|
9
|
-
def on_step(
|
|
10
|
-
@spinner = build_spinner("Dumping database #{args.first[:database_name]}")
|
|
9
|
+
def on_step(event)
|
|
10
|
+
@spinner = build_spinner("Dumping database #{event[:args].first[:database_name]}")
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def on_step_succeeded(
|
|
14
|
-
@spinner.success([success, value[:dump]].join(' '))
|
|
13
|
+
def on_step_succeeded(event)
|
|
14
|
+
@spinner.success([success, event[:value][:dump]].join(' '))
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -10,8 +10,8 @@ class PgExport
|
|
|
10
10
|
@spinner = build_spinner('Decrypting')
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def on_step_succeeded(
|
|
14
|
-
@spinner.success([success, value[:dump]].join(' '))
|
|
13
|
+
def on_step_succeeded(event)
|
|
14
|
+
@spinner.success([success, event[:value][:dump]].join(' '))
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -10,8 +10,8 @@ class PgExport
|
|
|
10
10
|
@spinner = build_spinner('Downloading')
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def on_step_succeeded(
|
|
14
|
-
@spinner.success([success, value[:dump]].join(' '))
|
|
13
|
+
def on_step_succeeded(event)
|
|
14
|
+
@spinner.success([success, event[:value][:dump]].join(' '))
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -10,8 +10,8 @@ class PgExport
|
|
|
10
10
|
@spinner = build_spinner('Encrypting')
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def on_step_succeeded(
|
|
14
|
-
@spinner.success([success, value[:dump]].join(' '))
|
|
13
|
+
def on_step_succeeded(event)
|
|
14
|
+
@spinner.success([success, event[:value][:dump]].join(' '))
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
end
|
data/lib/pg_export/lib/pg_export/listeners/interactive/{open_ftp_connection.rb → open_connection.rb}
RENAMED
|
@@ -5,7 +5,7 @@ require_relative '../interactive_listener'
|
|
|
5
5
|
class PgExport
|
|
6
6
|
module Listeners
|
|
7
7
|
class Interactive
|
|
8
|
-
class
|
|
8
|
+
class OpenConnection < InteractiveListener
|
|
9
9
|
def on_step(*)
|
|
10
10
|
@spinner = build_spinner('Opening ftp connection')
|
|
11
11
|
end
|
|
@@ -6,13 +6,13 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Interactive
|
|
8
8
|
class RemoveOldDumpsFromFtp < InteractiveListener
|
|
9
|
-
def on_step(
|
|
10
|
-
@spinner = build_spinner("Checking for old dumps on #{args.first[:
|
|
9
|
+
def on_step(event)
|
|
10
|
+
@spinner = build_spinner("Checking for old dumps on #{event[:args].first[:gateway]}")
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def on_step_succeeded(
|
|
14
|
-
if value[:removed_dumps].any?
|
|
15
|
-
@spinner.success([success, value[:removed_dumps].map { |filename| " #{filename} removed" }].join("\n"))
|
|
13
|
+
def on_step_succeeded(event)
|
|
14
|
+
if event[:value][:removed_dumps].any?
|
|
15
|
+
@spinner.success([success, event[:value][:removed_dumps].map { |filename| " #{filename} removed" }].join("\n"))
|
|
16
16
|
else
|
|
17
17
|
@spinner.success([success, 'nothing to remove'].join(' '))
|
|
18
18
|
end
|
|
@@ -6,8 +6,8 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Interactive
|
|
8
8
|
class Restore < InteractiveListener
|
|
9
|
-
def on_step(
|
|
10
|
-
@spinner = build_spinner("Restoring dump to database #{args.first[:database]}")
|
|
9
|
+
def on_step(event)
|
|
10
|
+
@spinner = build_spinner("Restoring dump to database #{event[:args].first[:database]}")
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def on_step_succeeded(*)
|
|
@@ -6,8 +6,8 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Interactive
|
|
8
8
|
class UploadDumpToFtp < InteractiveListener
|
|
9
|
-
def on_step(
|
|
10
|
-
@spinner = build_spinner("Uploading #{args.first[:dump]} to #{args.first[:
|
|
9
|
+
def on_step(event)
|
|
10
|
+
@spinner = build_spinner("Uploading #{event[:args].first[:dump]} to #{event[:args].first[:gateway]}")
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def on_step_succeeded(*)
|
|
@@ -8,8 +8,8 @@ require 'tty-spinner'
|
|
|
8
8
|
class PgExport
|
|
9
9
|
module Listeners
|
|
10
10
|
class InteractiveListener
|
|
11
|
-
def on_step_failed(
|
|
12
|
-
@spinner.error([error, self.class.red(value[:message])].join("\n"))
|
|
11
|
+
def on_step_failed(event)
|
|
12
|
+
@spinner.error([error, self.class.red(event[:value][:message])].join("\n"))
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
class << self
|
|
@@ -6,8 +6,8 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Plain
|
|
8
8
|
class BuildDump < PlainListener
|
|
9
|
-
def on_step_succeeded(
|
|
10
|
-
logger.info("Dump database #{value[:dump].database} to #{value[:dump]}")
|
|
9
|
+
def on_step_succeeded(event)
|
|
10
|
+
logger.info("Dump database #{event[:value][:dump].database} to #{event[:value][:dump]}")
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
data/lib/pg_export/lib/pg_export/listeners/plain/{close_ftp_connection.rb → close_connection.rb}
RENAMED
|
@@ -5,9 +5,9 @@ require_relative '../plain_listener'
|
|
|
5
5
|
class PgExport
|
|
6
6
|
module Listeners
|
|
7
7
|
class Plain
|
|
8
|
-
class
|
|
8
|
+
class CloseConnection < PlainListener
|
|
9
9
|
def on_step_succeeded(*)
|
|
10
|
-
logger.info('Close
|
|
10
|
+
logger.info('Close connection')
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -6,8 +6,8 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Plain
|
|
8
8
|
class DecryptDump < PlainListener
|
|
9
|
-
def on_step_succeeded(
|
|
10
|
-
logger.info("Decrypt #{value[:dump]}")
|
|
9
|
+
def on_step_succeeded(event)
|
|
10
|
+
logger.info("Decrypt #{event[:value][:dump]}")
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -6,8 +6,8 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Plain
|
|
8
8
|
class DownloadDumpFromFtp < PlainListener
|
|
9
|
-
def on_step_succeeded(
|
|
10
|
-
logger.info("Download #{value[:dump]}")
|
|
9
|
+
def on_step_succeeded(event)
|
|
10
|
+
logger.info("Download #{event[:value][:dump]}")
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -6,8 +6,8 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Plain
|
|
8
8
|
class EncryptDump < PlainListener
|
|
9
|
-
def on_step_succeeded(
|
|
10
|
-
logger.info("Encrypt #{value[:dump]}")
|
|
9
|
+
def on_step_succeeded(event)
|
|
10
|
+
logger.info("Encrypt #{event[:value][:dump]}")
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -6,8 +6,8 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Plain
|
|
8
8
|
class FetchDumpsFromFtp < PlainListener
|
|
9
|
-
def on_step_succeeded(
|
|
10
|
-
logger.info("Fetch dumps (#{value[:dumps].count} items)")
|
|
9
|
+
def on_step_succeeded(event)
|
|
10
|
+
logger.info("Fetch dumps (#{event[:value][:dumps].count} items)")
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../plain_listener'
|
|
4
|
+
|
|
5
|
+
class PgExport
|
|
6
|
+
module Listeners
|
|
7
|
+
class Plain
|
|
8
|
+
class OpenConnection < PlainListener
|
|
9
|
+
def on_step_succeeded(event)
|
|
10
|
+
logger.info("Connect to #{event[:value][:gateway]}")
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -6,9 +6,9 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Plain
|
|
8
8
|
class RemoveOldDumpsFromFtp < PlainListener
|
|
9
|
-
def on_step_succeeded(
|
|
10
|
-
value[:removed_dumps].each do |filename|
|
|
11
|
-
logger.info("Remove #{filename} from #{value[:
|
|
9
|
+
def on_step_succeeded(event)
|
|
10
|
+
event[:value][:removed_dumps].each do |filename|
|
|
11
|
+
logger.info("Remove #{filename} from #{event[:value][:gateway]}")
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -6,8 +6,8 @@ class PgExport
|
|
|
6
6
|
module Listeners
|
|
7
7
|
class Plain
|
|
8
8
|
class UploadDumpToFtp < PlainListener
|
|
9
|
-
def on_step_succeeded(
|
|
10
|
-
logger.info("Upload #{value[:dump]} to #{value[:
|
|
9
|
+
def on_step_succeeded(event)
|
|
10
|
+
logger.info("Upload #{event[:value][:dump]} to #{event[:value][:gateway]}")
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -9,8 +9,8 @@ class PgExport
|
|
|
9
9
|
class PlainListener
|
|
10
10
|
include Import['logger']
|
|
11
11
|
|
|
12
|
-
def on_step_failed(
|
|
13
|
-
logger.info("Error: #{value[:message]}")
|
|
12
|
+
def on_step_failed(event)
|
|
13
|
+
logger.info("Error: #{event[:value][:message]}")
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
end
|
|
@@ -5,14 +5,14 @@ require 'pg_export/import'
|
|
|
5
5
|
|
|
6
6
|
class PgExport
|
|
7
7
|
module Operations
|
|
8
|
-
class
|
|
8
|
+
class OpenConnection
|
|
9
9
|
include Dry::Transaction::Operation
|
|
10
|
-
include Import['factories.
|
|
10
|
+
include Import['factories.gateway_factory']
|
|
11
11
|
|
|
12
12
|
def call(inputs)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Success(inputs.merge(
|
|
13
|
+
gateway = gateway_factory.gateway
|
|
14
|
+
gateway.open
|
|
15
|
+
Success(inputs.merge(gateway: gateway))
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -7,19 +7,19 @@ class PgExport
|
|
|
7
7
|
module Operations
|
|
8
8
|
class RemoveOldDumpsFromFtp
|
|
9
9
|
include Dry::Transaction::Operation
|
|
10
|
-
include Import['repositories.
|
|
10
|
+
include Import['repositories.gateway_dump_repository', 'config']
|
|
11
11
|
|
|
12
|
-
def call(dump:,
|
|
13
|
-
dumps =
|
|
12
|
+
def call(dump:, gateway:)
|
|
13
|
+
dumps = gateway_dump_repository.by_database_name(
|
|
14
14
|
database_name: dump.database,
|
|
15
|
-
|
|
15
|
+
gateway: gateway,
|
|
16
16
|
offset: config.keep_dumps
|
|
17
17
|
)
|
|
18
18
|
dumps.each do |d|
|
|
19
|
-
|
|
19
|
+
gateway.delete(d.name)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
Success(removed_dumps: dumps,
|
|
22
|
+
Success(removed_dumps: dumps, gateway: gateway)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -7,10 +7,10 @@ require 'pg_export/lib/pg_export/value_objects/dump_file'
|
|
|
7
7
|
|
|
8
8
|
class PgExport
|
|
9
9
|
module Repositories
|
|
10
|
-
class
|
|
11
|
-
def by_name(name:,
|
|
10
|
+
class GatewayDumpFileRepository
|
|
11
|
+
def by_name(name:, gateway:)
|
|
12
12
|
file = ValueObjects::DumpFile.new
|
|
13
|
-
|
|
13
|
+
gateway.get(file, name)
|
|
14
14
|
|
|
15
15
|
file
|
|
16
16
|
end
|
data/lib/pg_export/lib/pg_export/repositories/{ftp_dump_repository.rb → gateway_dump_repository.rb}
RENAMED
|
@@ -7,21 +7,21 @@ require 'pg_export/lib/pg_export/value_objects/dump_file'
|
|
|
7
7
|
|
|
8
8
|
class PgExport
|
|
9
9
|
module Repositories
|
|
10
|
-
class
|
|
11
|
-
def all(database_name:,
|
|
12
|
-
|
|
10
|
+
class GatewayDumpRepository
|
|
11
|
+
def all(database_name:, gateway:)
|
|
12
|
+
gateway.list([database_name, '*'].compact.join('_')).map do |item|
|
|
13
13
|
begin
|
|
14
|
-
dump(name, database_name, size)
|
|
14
|
+
dump(item[:name], database_name, item[:size])
|
|
15
15
|
rescue Dry::Types::ConstraintError
|
|
16
16
|
nil
|
|
17
17
|
end
|
|
18
18
|
end.compact
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def by_database_name(database_name:,
|
|
22
|
-
|
|
21
|
+
def by_database_name(database_name:, gateway:, offset:)
|
|
22
|
+
gateway.list(database_name + '_*').drop(offset).map do |item|
|
|
23
23
|
begin
|
|
24
|
-
dump(name, database_name, size)
|
|
24
|
+
dump(item[:name], database_name, item[:size])
|
|
25
25
|
rescue Dry::Types::ConstraintError
|
|
26
26
|
nil
|
|
27
27
|
end
|
|
@@ -17,10 +17,10 @@ class PgExport
|
|
|
17
17
|
step :prepare_params
|
|
18
18
|
step :build_dump
|
|
19
19
|
step :encrypt_dump, with: 'operations.encrypt_dump'
|
|
20
|
-
step :
|
|
20
|
+
step :open_connection, with: 'operations.open_connection'
|
|
21
21
|
step :upload_dump_to_ftp
|
|
22
22
|
step :remove_old_dumps_from_ftp, with: 'operations.remove_old_dumps_from_ftp'
|
|
23
|
-
step :
|
|
23
|
+
step :close_connection
|
|
24
24
|
|
|
25
25
|
private
|
|
26
26
|
|
|
@@ -42,14 +42,14 @@ class PgExport
|
|
|
42
42
|
Failure(message: 'Unable to dump database: ' + e.to_s)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
def upload_dump_to_ftp(dump:,
|
|
46
|
-
|
|
47
|
-
Success(dump: dump,
|
|
45
|
+
def upload_dump_to_ftp(dump:, gateway:)
|
|
46
|
+
gateway.persist(dump.file, dump.name)
|
|
47
|
+
Success(dump: dump, gateway: gateway)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
def
|
|
51
|
-
|
|
52
|
-
Success(
|
|
50
|
+
def close_connection(removed_dumps:, gateway:)
|
|
51
|
+
gateway.close
|
|
52
|
+
Success(gateway: gateway)
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
end
|
|
@@ -13,41 +13,41 @@ class PgExport
|
|
|
13
13
|
include Dry::Transaction(container: PgExport::Container)
|
|
14
14
|
include Import[
|
|
15
15
|
'adapters.bash_adapter',
|
|
16
|
-
'repositories.
|
|
17
|
-
'repositories.
|
|
16
|
+
'repositories.gateway_dump_repository',
|
|
17
|
+
'repositories.gateway_dump_file_repository',
|
|
18
18
|
'ui_input'
|
|
19
19
|
]
|
|
20
20
|
|
|
21
|
-
step :
|
|
21
|
+
step :open_connection, with: 'operations.open_connection'
|
|
22
22
|
step :fetch_dumps_from_ftp
|
|
23
23
|
step :select_dump
|
|
24
24
|
step :download_dump_from_ftp
|
|
25
|
-
step :
|
|
25
|
+
step :close_connection
|
|
26
26
|
step :decrypt_dump, with: 'operations.decrypt_dump'
|
|
27
27
|
step :select_database
|
|
28
28
|
step :restore
|
|
29
29
|
|
|
30
30
|
private
|
|
31
31
|
|
|
32
|
-
def fetch_dumps_from_ftp(database_name:,
|
|
33
|
-
dumps =
|
|
32
|
+
def fetch_dumps_from_ftp(database_name:, gateway:)
|
|
33
|
+
dumps = gateway_dump_repository.all(database_name: database_name, gateway: gateway)
|
|
34
34
|
return Failure(message: 'No dumps') if dumps.none?
|
|
35
35
|
|
|
36
|
-
Success(
|
|
36
|
+
Success(gateway: gateway, dumps: dumps)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def select_dump(dumps:,
|
|
39
|
+
def select_dump(dumps:, gateway:)
|
|
40
40
|
dump = ui_input.select_dump(dumps)
|
|
41
|
-
Success(dump: dump,
|
|
41
|
+
Success(dump: dump, gateway: gateway)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
def download_dump_from_ftp(dump:,
|
|
45
|
-
dump.file =
|
|
46
|
-
Success(dump: dump,
|
|
44
|
+
def download_dump_from_ftp(dump:, gateway:)
|
|
45
|
+
dump.file = gateway_dump_file_repository.by_name(name: dump.name, gateway: gateway)
|
|
46
|
+
Success(dump: dump, gateway: gateway)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def
|
|
50
|
-
Thread.new {
|
|
49
|
+
def close_connection(dump:, gateway:)
|
|
50
|
+
Thread.new { gateway.close }
|
|
51
51
|
Success(dump: dump)
|
|
52
52
|
end
|
|
53
53
|
|
|
@@ -19,10 +19,10 @@ PgExport::Container.boot(:plain) do
|
|
|
19
19
|
%i[
|
|
20
20
|
build_dump
|
|
21
21
|
encrypt_dump
|
|
22
|
-
|
|
22
|
+
open_connection
|
|
23
23
|
upload_dump_to_ftp
|
|
24
24
|
remove_old_dumps_from_ftp
|
|
25
|
-
|
|
25
|
+
close_connection
|
|
26
26
|
].each do |step|
|
|
27
27
|
transaction.subscribe(step => target["listeners.#{type}.#{step}"])
|
|
28
28
|
end
|
data/lib/pg_export/version.rb
CHANGED
data/pg_export.gemspec
CHANGED
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
|
16
16
|
spec.homepage = 'https://github.com/maicher/pg_export'
|
|
17
17
|
spec.license = 'MIT'
|
|
18
18
|
|
|
19
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^
|
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
|
|
20
20
|
spec.executables = ['pg_export']
|
|
21
21
|
spec.require_paths = ['lib']
|
|
22
22
|
spec.required_ruby_version = '>= 2.3.0'
|
|
@@ -26,13 +26,15 @@ Gem::Specification.new do |spec|
|
|
|
26
26
|
spec.add_dependency 'dry-struct', '~> 1.0'
|
|
27
27
|
spec.add_dependency 'dry-system', '~> 0.18'
|
|
28
28
|
spec.add_dependency 'dry-transaction', '~> 0.13'
|
|
29
|
+
spec.add_dependency 'net-ssh'
|
|
30
|
+
spec.add_dependency 'net-scp'
|
|
29
31
|
spec.add_dependency 'tty-prompt'
|
|
30
32
|
spec.add_dependency 'tty-spinner'
|
|
31
33
|
|
|
32
34
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
|
33
35
|
spec.add_development_dependency 'pg', '~> 0.21'
|
|
34
36
|
spec.add_development_dependency 'pry'
|
|
35
|
-
spec.add_development_dependency 'rake', '
|
|
37
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
|
36
38
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
|
37
39
|
spec.add_development_dependency 'rubocop', '~> 0.59.2'
|
|
38
40
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pg_export
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0.rc1
|
|
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: 2021-03-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: dry-initializer
|
|
@@ -80,6 +80,34 @@ dependencies:
|
|
|
80
80
|
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0.13'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: net-ssh
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: net-scp
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :runtime
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
83
111
|
- !ruby/object:Gem::Dependency
|
|
84
112
|
name: tty-prompt
|
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -154,16 +182,16 @@ dependencies:
|
|
|
154
182
|
name: rake
|
|
155
183
|
requirement: !ruby/object:Gem::Requirement
|
|
156
184
|
requirements:
|
|
157
|
-
- - "
|
|
185
|
+
- - ">="
|
|
158
186
|
- !ruby/object:Gem::Version
|
|
159
|
-
version:
|
|
187
|
+
version: 12.3.3
|
|
160
188
|
type: :development
|
|
161
189
|
prerelease: false
|
|
162
190
|
version_requirements: !ruby/object:Gem::Requirement
|
|
163
191
|
requirements:
|
|
164
|
-
- - "
|
|
192
|
+
- - ">="
|
|
165
193
|
- !ruby/object:Gem::Version
|
|
166
|
-
version:
|
|
194
|
+
version: 12.3.3
|
|
167
195
|
- !ruby/object:Gem::Dependency
|
|
168
196
|
name: rspec
|
|
169
197
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -222,39 +250,41 @@ files:
|
|
|
222
250
|
- lib/pg_export/container.rb
|
|
223
251
|
- lib/pg_export/import.rb
|
|
224
252
|
- lib/pg_export/lib/pg_export/adapters/bash_adapter.rb
|
|
225
|
-
- lib/pg_export/lib/pg_export/adapters/ftp_adapter.rb
|
|
226
253
|
- lib/pg_export/lib/pg_export/entities/dump.rb
|
|
227
254
|
- lib/pg_export/lib/pg_export/factories/cipher_factory.rb
|
|
228
255
|
- lib/pg_export/lib/pg_export/factories/dump_factory.rb
|
|
229
|
-
- lib/pg_export/lib/pg_export/factories/
|
|
256
|
+
- lib/pg_export/lib/pg_export/factories/ftp_gateway_factory.rb
|
|
257
|
+
- lib/pg_export/lib/pg_export/factories/ssh_gateway_factory.rb
|
|
258
|
+
- lib/pg_export/lib/pg_export/gateways/ftp.rb
|
|
259
|
+
- lib/pg_export/lib/pg_export/gateways/ssh.rb
|
|
230
260
|
- lib/pg_export/lib/pg_export/listeners/interactive/build_dump.rb
|
|
231
|
-
- lib/pg_export/lib/pg_export/listeners/interactive/
|
|
261
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/close_connection.rb
|
|
232
262
|
- lib/pg_export/lib/pg_export/listeners/interactive/decrypt_dump.rb
|
|
233
263
|
- lib/pg_export/lib/pg_export/listeners/interactive/download_dump_from_ftp.rb
|
|
234
264
|
- lib/pg_export/lib/pg_export/listeners/interactive/encrypt_dump.rb
|
|
235
265
|
- lib/pg_export/lib/pg_export/listeners/interactive/fetch_dumps_from_ftp.rb
|
|
236
|
-
- lib/pg_export/lib/pg_export/listeners/interactive/
|
|
266
|
+
- lib/pg_export/lib/pg_export/listeners/interactive/open_connection.rb
|
|
237
267
|
- lib/pg_export/lib/pg_export/listeners/interactive/remove_old_dumps_from_ftp.rb
|
|
238
268
|
- lib/pg_export/lib/pg_export/listeners/interactive/restore.rb
|
|
239
269
|
- lib/pg_export/lib/pg_export/listeners/interactive/upload_dump_to_ftp.rb
|
|
240
270
|
- lib/pg_export/lib/pg_export/listeners/interactive_listener.rb
|
|
241
271
|
- lib/pg_export/lib/pg_export/listeners/plain/build_dump.rb
|
|
242
|
-
- lib/pg_export/lib/pg_export/listeners/plain/
|
|
272
|
+
- lib/pg_export/lib/pg_export/listeners/plain/close_connection.rb
|
|
243
273
|
- lib/pg_export/lib/pg_export/listeners/plain/decrypt_dump.rb
|
|
244
274
|
- lib/pg_export/lib/pg_export/listeners/plain/download_dump_from_ftp.rb
|
|
245
275
|
- lib/pg_export/lib/pg_export/listeners/plain/encrypt_dump.rb
|
|
246
276
|
- lib/pg_export/lib/pg_export/listeners/plain/fetch_dumps_from_ftp.rb
|
|
247
|
-
- lib/pg_export/lib/pg_export/listeners/plain/
|
|
277
|
+
- lib/pg_export/lib/pg_export/listeners/plain/open_connection.rb
|
|
248
278
|
- lib/pg_export/lib/pg_export/listeners/plain/remove_old_dumps_from_ftp.rb
|
|
249
279
|
- lib/pg_export/lib/pg_export/listeners/plain/restore.rb
|
|
250
280
|
- lib/pg_export/lib/pg_export/listeners/plain/upload_dump_to_ftp.rb
|
|
251
281
|
- lib/pg_export/lib/pg_export/listeners/plain_listener.rb
|
|
252
282
|
- lib/pg_export/lib/pg_export/operations/decrypt_dump.rb
|
|
253
283
|
- lib/pg_export/lib/pg_export/operations/encrypt_dump.rb
|
|
254
|
-
- lib/pg_export/lib/pg_export/operations/
|
|
284
|
+
- lib/pg_export/lib/pg_export/operations/open_connection.rb
|
|
255
285
|
- lib/pg_export/lib/pg_export/operations/remove_old_dumps_from_ftp.rb
|
|
256
|
-
- lib/pg_export/lib/pg_export/repositories/
|
|
257
|
-
- lib/pg_export/lib/pg_export/repositories/
|
|
286
|
+
- lib/pg_export/lib/pg_export/repositories/gateway_dump_file_repository.rb
|
|
287
|
+
- lib/pg_export/lib/pg_export/repositories/gateway_dump_repository.rb
|
|
258
288
|
- lib/pg_export/lib/pg_export/transactions/export_dump.rb
|
|
259
289
|
- lib/pg_export/lib/pg_export/transactions/import_dump_interactively.rb
|
|
260
290
|
- lib/pg_export/lib/pg_export/types.rb
|
|
@@ -282,11 +312,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
282
312
|
version: 2.3.0
|
|
283
313
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
314
|
requirements:
|
|
285
|
-
- - "
|
|
315
|
+
- - ">"
|
|
286
316
|
- !ruby/object:Gem::Version
|
|
287
|
-
version:
|
|
317
|
+
version: 1.3.1
|
|
288
318
|
requirements: []
|
|
289
|
-
rubygems_version: 3.
|
|
319
|
+
rubygems_version: 3.2.3
|
|
290
320
|
signing_key:
|
|
291
321
|
specification_version: 4
|
|
292
322
|
summary: CLI for creating and exporting PostgreSQL dumps to FTP.
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# auto_register: false
|
|
4
|
-
|
|
5
|
-
require 'pg_export/lib/pg_export/adapters/ftp_adapter'
|
|
6
|
-
require 'pg_export/import'
|
|
7
|
-
|
|
8
|
-
class PgExport
|
|
9
|
-
module Factories
|
|
10
|
-
class FtpAdapterFactory
|
|
11
|
-
include Import['config']
|
|
12
|
-
|
|
13
|
-
def ftp_adapter
|
|
14
|
-
::PgExport::Adapters::FtpAdapter.new(
|
|
15
|
-
host: config.ftp_host,
|
|
16
|
-
user: config.ftp_user,
|
|
17
|
-
password: config.ftp_password
|
|
18
|
-
)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../plain_listener'
|
|
4
|
-
|
|
5
|
-
class PgExport
|
|
6
|
-
module Listeners
|
|
7
|
-
class Plain
|
|
8
|
-
class OpenFtpConnection < PlainListener
|
|
9
|
-
def on_step_succeeded(step_name:, args:, value:)
|
|
10
|
-
logger.info("Connect to #{value[:ftp_adapter]}")
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|