pg_export 0.7.3 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +6 -3
- data/CHANGELOG.md +17 -0
- data/README.md +13 -10
- data/bin/pg_export +20 -7
- data/lib/pg_export/configuration.rb +12 -8
- 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/lib/pg_export/types.rb +1 -1
- 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 +10 -6
- metadata +84 -27
- 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
@@ -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
|
|