pg_backup 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8413fa19c76ce5651b2db1d6ad5a2e9b556e3e1e
4
- data.tar.gz: 74f811f636be76248699ac8d164c7fc4eb2cd1d9
3
+ metadata.gz: aae918d69fa35757f12220b03705420527a1e116
4
+ data.tar.gz: ba1e0cc7aafb5fbc540c732d05ff889cd2f80906
5
5
  SHA512:
6
- metadata.gz: e514eb5aebbeb3082ad1bb3533943ae13643a428be6f71e1aea18c58929f52b2ba2f5a3ab52476a65dd16fdc135050ad4888dcd7c40a09225a2a7e7c47aaf626
7
- data.tar.gz: 14f8a49fd277909205e4dcce3f7ff7bd122fbaf10f453e384cec619a8c5af5def9c5192429cf589c49dd3ea0059f5b2093a46a6b0b4810169fcd86a42191b165
6
+ metadata.gz: c67efdac865ea88bb4b36bfd9fad2ad098864b82d354ed7ed586dad80aaf9017a5e1659f6b307580b96960b8d4c2b5b00d9b961a29cc50ad6143268f9819318e
7
+ data.tar.gz: 13cd2f6e0a3477cd4c8a205f3301e235d19add91fa0ef9c7109cd4a76d0565713422582eb12846191c81602f6b5b5e03cd1cf131a33018e8e2196903cf936f1f
data/README.md CHANGED
@@ -29,7 +29,13 @@ rake pg_backup:dump:create # create a dump from local db and save it locally
29
29
  rake pg_backup:dump:load # import latest dump from local file into local db
30
30
  ```
31
31
 
32
- ### Capistrano integration
32
+ If you want to create or load a dump file from a different directory, use the ``` DUMP_DIR ``` env var:
33
+ ```
34
+ rake DUMP_DIR=my_dump_dir pg_backup:dump:create
35
+ rake DUMP_DIR=my_dump_dir pg_backup:dump:load
36
+ ```
37
+
38
+ ### Capistrano integration
33
39
  (https://github.com/capistrano/capistrano)
34
40
 
35
41
  add to your ```Capfile```
@@ -44,7 +50,13 @@ cap <env> pg_backup:dump:download # downloads latest remote dump to local dir
44
50
  cap <env> pg_backup:dump:upload # uploads latest local dump to remote dir
45
51
  ```
46
52
 
47
- ### deploy-mate integration
53
+ To overwrite dump directories in capistrano, place something like this in your deploy.rb or \<stage\>.rb
54
+ ```
55
+ set :pg_backup_local_dump_dir, 'my_dump_dir'
56
+ set :pg_backup_remote_dump_dir, 'my_dump_dir'
57
+ ```
58
+
59
+ ### deploy-mate integration
48
60
  (https://github.com/hanseventures/deploy-mate)
49
61
 
50
62
  add to your ```Capfile```
@@ -54,7 +66,6 @@ require "pg_backup/integration/deploy_mate"
54
66
  ```
55
67
 
56
68
  ## ToDo
57
- - allow change of dump dir (local and remote)
58
69
  - tests? https://github.com/technicalpickles/capistrano-spec
59
70
  - rotate local and remote dumps (keep last x dumps)
60
71
 
@@ -1,7 +1,10 @@
1
1
  namespace :load do
2
2
  task :defaults do
3
+ # set default names for dump directories
4
+ set :pg_backup_local_dump_dir, 'dump'
5
+ set :pg_backup_remote_dump_dir, 'dump'
3
6
  # add the dump dir to the linked directories
4
- set :linked_dirs, fetch(:linked_dirs, []).push('dump')
7
+ set :linked_dirs, fetch(:linked_dirs, []).push(fetch(:pg_backup_remote_dump_dir))
5
8
  end
6
9
  end
7
10
 
@@ -12,7 +15,7 @@ namespace :pg_backup do
12
15
  task :load do
13
16
  on roles(:app) do
14
17
  within current_path do
15
- with rails_env: fetch(:environment) do
18
+ with rails_env: fetch(:environment), dump_dir: fetch(:pg_backup_remote_dump_dir) do
16
19
  ask :answer, "Are you sure? This overwrites the '#{fetch(:environment)}' database! Type 'YES' if you want to continue..."
17
20
  if fetch(:answer) == "YES"
18
21
  rake "pg_backup:dump:load"
@@ -28,7 +31,7 @@ namespace :pg_backup do
28
31
  task :create do
29
32
  on roles(:app) do
30
33
  within current_path do
31
- with rails_env: fetch(:environment) do
34
+ with rails_env: fetch(:environment), dump_dir: fetch(:pg_backup_remote_dump_dir) do
32
35
  rake "pg_backup:dump:create"
33
36
  end
34
37
  end
@@ -38,12 +41,12 @@ namespace :pg_backup do
38
41
  desc "Upload latest db dump from (local) dump dir"
39
42
  task :upload do
40
43
  on roles(:app) do
41
- within shared_path do
44
+ within current_path do
42
45
  with rails_env: fetch(:environment) do
43
- file_path = Dir.glob("#{ENV.fetch('PWD')}/dump/*.backup").last
46
+ file_path = Dir.glob("#{ENV.fetch('PWD')}/#{fetch(:pg_backup_local_dump_dir)}/*.backup").last
44
47
  fail "Can't find a dump file!" unless file_path
45
48
  file_name = File.basename file_path
46
- upload! file_path, "#{shared_path}/dump/#{file_name}"
49
+ upload! file_path, "#{shared_path}/#{fetch(:pg_backup_remote_dump_dir)}/#{file_name}"
47
50
  end
48
51
  end
49
52
  end
@@ -52,12 +55,12 @@ namespace :pg_backup do
52
55
  desc "Download remote db dump"
53
56
  task :download do
54
57
  on roles(:app) do
55
- within shared_path do
58
+ within current_path do
56
59
  with rails_env: fetch(:environment) do
57
- file_name = capture("ls -t #{shared_path}/dump | head -1")
60
+ file_name = capture("ls -t #{shared_path}/#{fetch(:pg_backup_remote_dump_dir)} | head -1")
58
61
  # TODO: exit if there is no dump
59
62
  # TODO: ensure dump dir
60
- download! "#{shared_path}/dump/#{file_name}", "dump"
63
+ download! "#{shared_path}/#{fetch(:pg_backup_remote_dump_dir)}/#{file_name}", "#{fetch(:pg_backup_local_dump_dir)}"
61
64
  end
62
65
  end
63
66
  end
@@ -6,25 +6,33 @@ namespace :pg_backup do
6
6
 
7
7
  desc "Load dumped postgres backup file "
8
8
  task load: :environment do
9
- file_name = Dir.glob("#{Rails.root}/dump/*.backup").sort.last
10
- fail "Can't find a dump file!" unless file_name
11
- puts "Loading dump file from #{file_name}..."
9
+ file_name = Dir.glob("#{Rails.root}/#{dump_dir}/*.backup").sort.last
10
+ fail "[pg_backup:dump:load] Can't find a dump file!" unless file_name
11
+ say "[pg_backup:dump:load] Loading dump file from #{file_name}..."
12
12
  with_database_config do |host, db, user, pw|
13
13
  %x{ PGPASSWORD=#{pw} pg_restore --host #{host} --username #{user} --schema public --no-owner --no-acl --clean --dbname #{db} #{file_name} }
14
14
  end
15
- puts "Done."
15
+ say "[pg_backup:dump:load] Done."
16
16
  end
17
17
 
18
18
  desc "Create dump from postgres db"
19
19
  task create: :environment do
20
- puts "Creating dump file..."
21
- FileUtils.mkdir_p Rails.root.join("dump")
22
- file_name = Rails.root.join("dump", "dump-#{Time.now.to_i}.backup")
20
+ say "[pg_backup:dump:create] Creating dump file..."
21
+ FileUtils.mkdir_p Rails.root.join(dump_dir)
22
+ file_name = Rails.root.join(dump_dir, "dump-#{Time.now.to_i}.backup")
23
23
  with_database_config do |host, db, user, pw|
24
24
  %x{ PGPASSWORD=#{pw} pg_dump --host #{host} --username #{user} --clean --format=c --no-owner --no-acl #{db} > #{file_name} }
25
25
  end
26
- puts "Dump file located at #{file_name}."
27
- puts "Done."
26
+ say "[pg_backup:dump:create] New dump file located at #{file_name}."
27
+ say "[pg_backup:dump:create] Done."
28
+ end
29
+
30
+ def dump_dir
31
+ ENV["DUMP_DIR"] || "dump" # default to 'dump' folder as dump dir
32
+ end
33
+
34
+ def say(text)
35
+ respond_to?(:info) ? info(text) : puts(text)
28
36
  end
29
37
 
30
38
  end
@@ -1,3 +1,3 @@
1
1
  module PgBackup
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Geissler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-13 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.2.2
98
+ rubygems_version: 2.4.3
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Create, restore, download and upload postgres dumps locally and on remote