postmodern 0.0.6 → 0.0.7

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
  SHA1:
3
- metadata.gz: b6751185ec42ad83428d20347ec925ecca99080a
4
- data.tar.gz: e2055ed0ca440c7739ccda5d1a4e1687a64c1ef7
3
+ metadata.gz: f405030c5dbf5f51a061e1ff2835e4a64910ce50
4
+ data.tar.gz: 915def7fe244751c7bba0a86601c225f89c7e706
5
5
  SHA512:
6
- metadata.gz: 67846656007c0e10721af39593d07ad28fe93a15fd3a1a17f6a13874a6ea232f5fdcf14f7e508634d71453e1bd2ee06d030495d84027c44c234b6503eebd04da
7
- data.tar.gz: db5af7acb228f891ae5e447bbb3259298308134fd8f564e97f078539fcff59c08e7ff6076e8b45d5256236edfeac1d553af762e756cdd98dedfc9572d1897da5
6
+ metadata.gz: 5850bf34a46775aa89ac3dcd5d95d1485e424c75bf05f710a29f4e4373da32dc250c8ff9c3428b4fae46e5f9c359c92d5825431fdd1517251a913a61770a46f5
7
+ data.tar.gz: ef083017586db98680ceb3fd7f55dfc9a3940c820c809958d915847efe2115916aefbffc486f828cbcdf65a69ee1b58374ac6de0732187a9e93a33cbb019f41e
data/README.md CHANGED
@@ -24,13 +24,13 @@ wrappers for YOUR archiving mechanism.
24
24
  In postgresql.conf
25
25
 
26
26
  ```
27
- archive_command = 'pg_wal_archive %p %f'
27
+ archive_command = 'postmodern archive --path %p --filename %f'
28
28
  ```
29
29
 
30
30
  In recovery.conf
31
31
 
32
32
  ```
33
- restore_command = 'pg_wal_restore %p %f'
33
+ restore_command = 'postmodern restore --path %p --filename %f'
34
34
  ```
35
35
 
36
36
  By default these scripts will do nothing. With the presence of local
@@ -39,15 +39,15 @@ exported to the environment and the local scripts called (with arguments
39
39
  preserved):
40
40
 
41
41
  ```ruby
42
- ENV['WAL_ARCHIVE_PATH'] = ARGV[0]
43
- ENV['WAL_ARCHIVE_FILE'] = ARGV[1]
42
+ ENV['WAL_ARCHIVE_PATH'] = path
43
+ ENV['WAL_ARCHIVE_FILE'] = filename
44
44
  ```
45
45
 
46
46
  Local scripts can be written in any language. They should be able access
47
47
  the relevant arguments either as $1, $2 or using the variables listed above.
48
48
 
49
- `pg_wal_archive` will attempt to call a `pg_wal_archive.local` script.
50
- `pg_wal_restore` will attempt to call a `pg_wal_restore.local` script.
49
+ `archive` will attempt to call a `postmodern_archive.local` script.
50
+ `restore` will attempt to call a `postmodern_restore.local` script.
51
51
 
52
52
 
53
53
  ## Contributing
data/bin/postmodern ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'postmodern/wal'
6
+ require 'optparse'
7
+
8
+ options = {}
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: postmodern (archive|restore) <options>"
11
+
12
+ opts.on('-f', '--filename FILE', 'File name to archive') do |o|
13
+ options[:file] = o
14
+ end
15
+
16
+ opts.on('-p', '--path PATH', 'Path name of file to archive') do |o|
17
+ options[:path] = o
18
+ end
19
+ end.parse!
20
+
21
+ Postmodern::WAL.run(ARGV.first, options[:file], options[:path])
@@ -1,3 +1,3 @@
1
1
  module Postmodern
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require 'postmodern/wal/archive'
2
+ require 'postmodern/wal/restore'
3
+
4
+ module Postmodern
5
+ module WAL
6
+ COMMANDS = {
7
+ 'archive' => Postmodern::WAL::Archive,
8
+ 'restore' => Postmodern::WAL::Restore
9
+ }
10
+
11
+ def self.run(command, filename, path)
12
+ COMMANDS[command].new(filename, path).run
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'base'
2
+
3
+ module Postmodern
4
+ module WAL
5
+ class Archive < Base
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,38 @@
1
+ module Postmodern
2
+ module WAL
3
+ class Base
4
+ attr_reader :filename, :path
5
+
6
+ def initialize(filename, path)
7
+ @filename = filename
8
+ @path = path
9
+
10
+ ENV['WAL_ARCHIVE_PATH'] = path
11
+ ENV['WAL_ARCHIVE_FILE'] = filename
12
+ end
13
+
14
+ def run
15
+ if local_script_exists?
16
+ log
17
+ `#{local_script} #{path} #{filename}`
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def local_script_exists?
24
+ `which #{local_script} >/dev/null 2>/dev/null`
25
+ $?.exitstatus == 0
26
+ end
27
+
28
+ def local_script
29
+ 'postmodern_archive.local'
30
+ end
31
+
32
+ def log
33
+ puts "Archiving file: #{filename}, path: #{path}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,18 @@
1
+ require_relative 'base'
2
+
3
+ module Postmodern
4
+ module WAL
5
+ class Restore < Base
6
+ private
7
+
8
+ def local_script
9
+ 'postmodern_restore.local'
10
+ end
11
+
12
+ def log
13
+ puts "Restoring file: #{filename}, path: #{path}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'postmodern' do
4
+ describe 'archive' do
5
+ let(:command) { `bin/postmodern archive --path filepath --filename filename` }
6
+
7
+ before do
8
+ double_cmd('postmodern_archive.local')
9
+ double_cmd('which', exit: 0)
10
+ end
11
+
12
+ it 'exports second argument as WAL_ARCHIVE_FILE' do
13
+ expect(command).to include('Archiving file: filename')
14
+ end
15
+
16
+ it 'exports first argument WAL_ARCHIVE_PATH' do
17
+ expect(command).to include('path: filepath')
18
+ end
19
+
20
+ context 'when local script is present' do
21
+ before { double_cmd('which postmodern_archive.local', exit: 0) }
22
+
23
+ it 'succeeds' do
24
+ expect { command }.to have_exit_status(0)
25
+ end
26
+
27
+ it 'calls a local file with file name and path' do
28
+ expect { command }.to shellout('postmodern_archive.local filepath filename')
29
+ end
30
+ end
31
+
32
+ context 'when local script is not present' do
33
+ before { double_cmd('which postmodern_archive.local', exit: 1) }
34
+
35
+ it 'succeeds' do
36
+ expect { command }.to have_exit_status(0)
37
+ end
38
+
39
+ it 'does nothing' do
40
+ expect { command }.not_to shellout('pg_wal_archive.local filepath filename')
41
+ end
42
+ end
43
+ end
44
+
45
+ describe 'restore' do
46
+ let(:command) { `bin/postmodern restore --path filepath --filename filename` }
47
+
48
+ before do
49
+ double_cmd('postmodern_restore.local')
50
+ double_cmd('which', exit: 0)
51
+ end
52
+
53
+ it 'exports second argument as WAL_restore_FILE' do
54
+ expect(command).to include('Restoring file: filename')
55
+ end
56
+
57
+ it 'exports first argument WAL_restore_PATH' do
58
+ expect(command).to include('path: filepath')
59
+ end
60
+
61
+ context 'when local script is present' do
62
+ before { double_cmd('which postmodern_restore.local', exit: 0) }
63
+
64
+ it 'succeeds' do
65
+ expect { command }.to have_exit_status(0)
66
+ end
67
+
68
+ it 'calls a local file with file name and path' do
69
+ expect { command }.to shellout('postmodern_restore.local filepath filename')
70
+ end
71
+ end
72
+
73
+ context 'when local script is not present' do
74
+ before { double_cmd('which postmodern_restore.local', exit: 1) }
75
+
76
+ it 'succeeds' do
77
+ expect { command }.to have_exit_status(0)
78
+ end
79
+
80
+ it 'does nothing' do
81
+ expect { command }.not_to shellout('pg_wal_restore.local filepath filename')
82
+ end
83
+ end
84
+ end
85
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmodern
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Saxby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,8 +42,7 @@ description: Tools for managing PostgreSQL
42
42
  email:
43
43
  - sax@livinginthepast.org
44
44
  executables:
45
- - pg_wal_archive
46
- - pg_wal_restore
45
+ - postmodern
47
46
  extensions: []
48
47
  extra_rdoc_files: []
49
48
  files:
@@ -55,13 +54,15 @@ files:
55
54
  - LICENSE.txt
56
55
  - README.md
57
56
  - Rakefile
58
- - bin/pg_wal_archive
59
- - bin/pg_wal_restore
57
+ - bin/postmodern
60
58
  - lib/postmodern.rb
61
59
  - lib/postmodern/version.rb
60
+ - lib/postmodern/wal.rb
61
+ - lib/postmodern/wal/archive.rb
62
+ - lib/postmodern/wal/base.rb
63
+ - lib/postmodern/wal/restore.rb
62
64
  - postmodern.gemspec
63
- - spec/bin/pg_wal_archive_spec.rb
64
- - spec/bin/pg_wal_restore_spec.rb
65
+ - spec/bin/postmodern_spec.rb
65
66
  - spec/spec_helper.rb
66
67
  homepage: https://github.com/wanelo/postmodern
67
68
  licenses:
@@ -88,7 +89,6 @@ signing_key:
88
89
  specification_version: 4
89
90
  summary: Tools for managing PostgreSQL
90
91
  test_files:
91
- - spec/bin/pg_wal_archive_spec.rb
92
- - spec/bin/pg_wal_restore_spec.rb
92
+ - spec/bin/postmodern_spec.rb
93
93
  - spec/spec_helper.rb
94
94
  has_rdoc:
data/bin/pg_wal_archive DELETED
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # This script is a wrapper for a user-generated pg_wal_archive.local
4
- # script. If that script does not exist, this executable does nothing
5
- # and WAL files are not archived.
6
- #
7
- # This script (and the local script) should be executable as the
8
- # postgres user.
9
-
10
- archive_path = ARGV[0]
11
- archive_file = ARGV[1]
12
-
13
- ENV['WAL_ARCHIVE_PATH']=archive_path # maps to %p in postgres archiving
14
- ENV['WAL_ARCHIVE_FILE']=archive_file # maps to %f in postgres archiving
15
-
16
- puts "Archiving file: #{archive_file}, path: #{archive_path}"
17
-
18
- def local_script_exists?
19
- `which pg_wal_archive.local >/dev/null 2>/dev/null`
20
- $?.exitstatus == 0
21
- end
22
-
23
- if local_script_exists?
24
- `pg_wal_archive.local #{archive_path} #{archive_file}`
25
- end
data/bin/pg_wal_restore DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- archive_path = ARGV[0]
4
- archive_file = ARGV[1]
5
-
6
- ENV['WAL_ARCHIVE_PATH']=archive_path # maps to %p in postgres archiving
7
- ENV['WAL_ARCHIVE_FILE']=archive_file # maps to %f in postgres archiving
8
-
9
- puts "Archiving file: #{archive_file}, path: #{archive_path}"
10
-
11
- def local_script_exists?
12
- `which pg_wal_restore.local >/dev/null 2>/dev/null`
13
- $?.exitstatus == 0
14
- end
15
-
16
- if local_script_exists?
17
- `pg_wal_restore.local #{archive_path} #{archive_file}`
18
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'pg_wal_archive' do
4
- before do
5
- double_cmd('pg_wal_archive.local')
6
- double_cmd('which', exit: 1)
7
- end
8
-
9
- it 'exports second argument as WAL_ARCHIVE_FILE' do
10
- expect(`bin/pg_wal_archive filepath filename`).to include('Archiving file: filename')
11
- end
12
-
13
- it 'exports first argument WAL_ARCHIVE_PATH' do
14
- expect(`bin/pg_wal_archive filepath filename`).to include('path: filepath')
15
- end
16
-
17
- context 'when local script is present' do
18
- before { double_cmd('which pg_wal_archive.local', exit: 0) }
19
-
20
- it 'succeeds' do
21
- expect { `bin/pg_wal_archive 1 2` }.to have_exit_status(0)
22
- end
23
-
24
- it 'calls a local file with file name and path' do
25
- expect {
26
- `bin/pg_wal_archive 11111 222222`
27
- }.to shellout('pg_wal_archive.local 11111 222222')
28
- end
29
- end
30
-
31
- context 'when local script is not present' do
32
- before { double_cmd('which pg_wal_archive.local', exit: 1) }
33
-
34
- it 'succeeds' do
35
- expect { `bin/pg_wal_archive 1 2` }.to have_exit_status(0)
36
- end
37
-
38
- it 'does nothing' do
39
- expect {
40
- `bin/pg_wal_archive 11111 222222`
41
- }.not_to shellout('pg_wal_archive.local 11111 222222')
42
- end
43
- end
44
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'pg_wal_restore' do
4
- before do
5
- double_cmd('pg_wal_restore.local')
6
- double_cmd('which')
7
- end
8
-
9
- it 'exports second argument as WAL_ARCHIVE_FILE' do
10
- expect(`bin/pg_wal_restore filepath filename`).to include('Archiving file: filename')
11
- end
12
-
13
- it 'exports first argument as WAL_ARCHIVE_PATH' do
14
- expect(`bin/pg_wal_restore filepath filename`).to include('path: filepath')
15
- end
16
-
17
- context 'when local script exists' do
18
- before { double_cmd('which pg_wal_restore.local', exit: 0) }
19
-
20
- it 'succeeds' do
21
- expect {`bin/pg_wal_restore 1 2`}.to have_exit_status(0)
22
- end
23
-
24
- it 'calls a local file with file name and path' do
25
- expect {
26
- `bin/pg_wal_restore 11111 222222`
27
- }.to shellout('pg_wal_restore.local 11111 222222')
28
- end
29
- end
30
-
31
- context 'when local script does not exists' do
32
- before { double_cmd('which pg_wal_restore.local', exit: 1) }
33
-
34
- it 'succeeds' do
35
- expect {`bin/pg_wal_restore 1 2`}.to have_exit_status(0)
36
- end
37
-
38
- it 'does nothing' do
39
- expect {
40
- `bin/pg_wal_restore 11111 222222`
41
- }.not_to shellout('pg_wal_restore.local')
42
- end
43
- end
44
- end