pg_export 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3eb793296ca1e2e22519a8abf1644f88fd06daa02a672d392f318a19128c50cb
4
- data.tar.gz: '085a37ec1e0b7cc96f811e73a0a3271086e1c12fba3e6a2da831c6f58a4f9fde'
3
+ metadata.gz: 96c2a7a23f195dba8cb7e21e3de8d9d130fd5849291e68ed153892b1f9e7aef6
4
+ data.tar.gz: 6f3fe11961d2d6b2089b6abacf93a1f37e48deee88d697c8402a9ac73b3dbbd3
5
5
  SHA512:
6
- metadata.gz: a3b89d600dc035cca7cdc909b503ac1d62e7844531d5f8a35c8213339968074ccb21d49669a1623f3d616f0aa52c2ccfb1c6c0a54f864e602ffcbe32a43c0886
7
- data.tar.gz: 9a93edd9855a3a20d5745491cedbcff104cd8aee180e1c10537c63c129c8ed96933f36d5120476b85812aece2bcaba507391910e282097b5a8555e210a0e209e
6
+ metadata.gz: 320d541ded251f9053bffa686fb429e22572b306f48227cb9b51aaa4bae76fd452ce2ab8e8f84ac63a0b1b4628bc8c70fbfbfb26d2295d5fc7bd1c1f9188330f
7
+ data.tar.gz: db3b2d4799b5ddc7e0628070b8d99406655d7fc3111a34a93dc8237a189ea01ef004a72d8ed2716ad03d74b901ec597d4dc796c9e893b0557e0f698639788a48
data/CHANGELOG.md CHANGED
@@ -6,6 +6,7 @@
6
6
  - BACKUP_FTP_PASSWORD -> PG_EXPORT_GATEWAY_PASSWORD
7
7
  - DUMP_ENCRYPTION_KEY -> PG_EXPORT_ENCRYPTION_KEY
8
8
  - Drop Ruby 2.3 support
9
+ - Add SSH option
9
10
 
10
11
  ### 0.7.7 - 2020.09.07
11
12
 
data/README.md CHANGED
@@ -74,7 +74,7 @@ __Step 1.__ Prepare ENV variables.
74
74
  PG_EXPORT_GATEWAY_USER=user
75
75
  PG_EXPORT_GATEWAY_PASSWORD=password
76
76
 
77
- /* Encryption key shoul have exactly 16 characters. */
77
+ /* Encryption key should have exactly 16 characters. */
78
78
  /* Dumps will be SSL(AES-128-CBC) encrypted using this key. */
79
79
  PG_EXPORT_ENCRYPTION_KEY=1234567890abcdef
80
80
 
data/bin/pg_export CHANGED
@@ -11,30 +11,58 @@ ENV['GATEWAY'] = 'ftp'
11
11
  interactive = false
12
12
  database = nil
13
13
 
14
+
14
15
  option_parser = OptionParser.new do |opts|
15
- opts.banner = 'Usage: pg_export [options]'
16
+ opts.banner = <<~TXT
17
+ NAME
18
+ pg_export - CLI for exporting/importing PostgreSQL dumps via FTP/SSH
19
+
20
+ SYNOPSIS (default mode)
21
+ pg_export DATABASE [options]
22
+
23
+ SYNOPSIS (interactive mode)
24
+ pg_export --interactive [DATABASE] [options]
25
+
26
+ ARGUMENTS
27
+ DATABASE - database name to export (when default mode)
28
+ - phrase to filter database dumps by (when interactive mode)
29
+
30
+ OPTIONS
31
+ TXT
16
32
 
17
- opts.on('-g', '--gateway GATEWAY', String, '[Optional] ssh or ftp (default: ftp)') do |g|
33
+ opts.on('-g', '--gateway GATEWAY', String, 'ssh or ftp (default: ftp) - credentials need to be set via ENVs') do |g|
18
34
  ENV['GATEWAY'] = g
19
35
  end
20
36
 
21
- opts.on('-d', '--database DATABASE', String, '[Required] Name of the database to export') do |d|
37
+ opts.on('-s', '--ssh', 'Same as "--gateway ssh"') do
38
+ ENV['GATEWAY'] = 'ssh'
39
+ end
40
+
41
+ opts.on('-f', '--ftp', 'Same as "--gateway ftp"') do
42
+ ENV['GATEWAY'] = 'ftp'
43
+ end
44
+
45
+ opts.on('-d', '--database DATABASE', String, 'Alternative way of specifying name of the database to export or phrase to filter by') do |d|
22
46
  database = d
23
47
  end
24
48
 
25
- opts.on('-k', '--keep [KEEP]', String, "[Optional] Number of dump files to keep on FTP (default: #{ENV['KEEP_DUMPS']})") do |keep|
49
+ opts.on('-e', '--encryption_key KEY', String, 'Dumps will be SSL(AES-128-CBC) encrypted using this key. Should have exactly 16 characters. Overwrites PG_EXPORT_ENCRYPTION_KEY env') do |key|
50
+ ENV['PG_EXPORT_ENCRYPTION_KEY'] = key
51
+ end
52
+
53
+ opts.on('-k', '--keep KEEP', String, "Number of dump files to keep on FTP (default: 10). Overwrites KEEP_DUMPS env") do |keep|
26
54
  ENV['KEEP_DUMPS'] = keep
27
55
  end
28
56
 
29
- opts.on('-t', '--timestamped', '[Optional] Enables log messages with timestamps') do
57
+ opts.on('-t', '--timestamped', 'Enables log messages with timestamps') do
30
58
  ENV['LOGGER_FORMAT'] = 'timestamped'
31
59
  end
32
60
 
33
- opts.on('-m', '--muted', '[Optional] Mutes log messages (overrides -t option)') do
61
+ opts.on('-m', '--muted', 'Mutes log messages (overrides -t option)') do
34
62
  ENV['LOGGER_FORMAT'] = 'muted'
35
63
  end
36
64
 
37
- opts.on('-i', '--interactive', '[Optional] Interactive command line mode - for restoring dumps into databases') do
65
+ opts.on('-i', '--interactive', 'Interactive mode, for importing dumps') do
38
66
  interactive = true
39
67
  end
40
68
 
@@ -48,29 +76,44 @@ option_parser = OptionParser.new do |opts|
48
76
  exit
49
77
  end
50
78
 
51
- opts.separator "\nSetting can be verified by running following commands:"
79
+ opts.separator <<~TXT
80
+
81
+ ENV
82
+ PG_EXPORT_GATEWAY_HOST required
83
+ PG_EXPORT_GATEWAY_USER required
84
+ PG_EXPORT_GATEWAY_PASSWORD optional when eg. authorized key is added
85
+ PG_EXPORT_ENCRYPTION_KEY required or set by --encryption_key)
86
+ TXT
87
+
88
+ opts.separator "\nTEST RUN"
52
89
 
53
- opts.on('-c', '--configuration', 'Prints the configuration') do
90
+ opts.on('-c', '--configuration', 'Print the configuration') do
54
91
  require 'pg_export/container'
55
92
  PgExport::Container.start(:config)
56
93
  puts PgExport::Container['config'].to_h
57
94
  exit
58
95
  end
59
96
 
60
- opts.on('-w', '--welcome', 'Tries connecting to the gateway (FTP or SSH) to verify the connection') do
97
+ opts.on('-w', '--welcome', 'Try connecting to the gateway (FTP or SSH) to verify the connection') do
61
98
  require 'pg_export/container'
62
99
  PgExport::Container.start(ENV['GATEWAY'].to_sym)
63
100
  gateway = PgExport::Container['factories.gateway_factory'].gateway
64
101
  puts gateway.welcome
65
102
  exit
66
103
  end
104
+
105
+ if ARGV.empty?
106
+ puts opts
107
+ exit
108
+ end
67
109
  end
68
110
 
69
111
  begin
70
112
  option_parser.parse!
113
+ database = ARGV.first unless ARGV.empty?
71
114
  rescue OptionParser::ParseError => e
72
115
  warn e.message.capitalize
73
- warn 'Type "pg_export -h" for available options'
116
+ warn 'Type "pg_export" for available options'
74
117
  exit
75
118
  end
76
119
 
@@ -27,9 +27,9 @@ class PgExport
27
27
  @ftp&.close
28
28
  end
29
29
 
30
- def list(regex_string)
30
+ def list(name)
31
31
  ftp
32
- .list(regex_string)
32
+ .list([name, '*'].join('_'))
33
33
  .map { |row| extracted_meaningful_attributes(row) }
34
34
  .sort_by { |item| item[:name] }
35
35
  .reverse
@@ -2,6 +2,7 @@
2
2
 
3
3
  # auto_register: false
4
4
 
5
+ require 'ed25519'
5
6
  require 'net/ssh'
6
7
  require 'net/scp'
7
8
 
@@ -30,11 +31,18 @@ class PgExport
30
31
  @ssh&.close
31
32
  end
32
33
 
33
- def list(regex_string)
34
+ def list(name)
35
+ grep =
36
+ if name.nil? || name.empty?
37
+ ''
38
+ else
39
+ " | grep #{name}"
40
+ end
41
+
34
42
  ssh
35
- .exec!("ls -l | grep #{regex_string.gsub('*', '')}")
36
- .split("\n")
37
- .map { |row| extract_meaningful_attributes(row) }
43
+ .exec!("ls -l#{grep}")
44
+ .split("\n").map { |row| extract_meaningful_attributes(row) }
45
+ .reject { |item| item[:name].nil? }
38
46
  .sort_by { |item| item[:name] }
39
47
  .reverse
40
48
  end
@@ -9,7 +9,7 @@ class PgExport
9
9
  module Repositories
10
10
  class GatewayDumpRepository
11
11
  def all(database_name:, gateway:)
12
- gateway.list([database_name, '*'].compact.join('_')).map do |item|
12
+ gateway.list(database_name).map do |item|
13
13
  begin
14
14
  dump(item[:name], database_name, item[:size])
15
15
  rescue Dry::Types::ConstraintError
@@ -19,7 +19,7 @@ class PgExport
19
19
  end
20
20
 
21
21
  def by_database_name(database_name:, gateway:, offset:)
22
- gateway.list(database_name + '_*').drop(offset).map do |item|
22
+ gateway.list(database_name).drop(offset).map do |item|
23
23
  begin
24
24
  dump(item[:name], database_name, item[:size])
25
25
  rescue Dry::Types::ConstraintError
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PgExport
4
- VERSION = '1.0.0.rc1'
4
+ VERSION = '1.0.0.rc2'
5
5
  end
data/pg_export.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['Krzysztof Maicher']
11
11
  spec.email = ['krzysztof.maicher@gmail.com']
12
12
 
13
- spec.summary = 'CLI for creating and exporting PostgreSQL dumps to FTP.'
14
- spec.description = "CLI for creating and exporting PostgreSQL dumps to FTP.\
13
+ spec.summary = 'CLI for exporting/importing PostgreSQL dumps via FTP/SSH.'
14
+ spec.description = "CLI for exporting/importing PostgreSQL dumps via FTP/SSH.\
15
15
  Can be used for backups or synchronizing databases between production and development environments."
16
16
  spec.homepage = 'https://github.com/maicher/pg_export'
17
17
  spec.license = 'MIT'
@@ -26,6 +26,7 @@ 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 'ed25519'
29
30
  spec.add_dependency 'net-ssh'
30
31
  spec.add_dependency 'net-scp'
31
32
  spec.add_dependency 'tty-prompt'
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: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Maicher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-20 00:00:00.000000000 Z
11
+ date: 2021-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-initializer
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ed25519
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'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: net-ssh
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -220,7 +234,7 @@ dependencies:
220
234
  - - "~>"
221
235
  - !ruby/object:Gem::Version
222
236
  version: 0.59.2
223
- description: CLI for creating and exporting PostgreSQL dumps to FTP. Can
237
+ description: CLI for exporting/importing PostgreSQL dumps via FTP/SSH. Can
224
238
  be used for backups or synchronizing databases between production and development
225
239
  environments.
226
240
  email:
@@ -319,5 +333,5 @@ requirements: []
319
333
  rubygems_version: 3.2.3
320
334
  signing_key:
321
335
  specification_version: 4
322
- summary: CLI for creating and exporting PostgreSQL dumps to FTP.
336
+ summary: CLI for exporting/importing PostgreSQL dumps via FTP/SSH.
323
337
  test_files: []