pg_backup 0.0.1 → 0.0.2

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: f66072498adffba3bf660e3522330afd5e8b4060
4
- data.tar.gz: 3827539bea4c8be2a97321d0e54cc9636fbc6fdf
3
+ metadata.gz: 8413fa19c76ce5651b2db1d6ad5a2e9b556e3e1e
4
+ data.tar.gz: 74f811f636be76248699ac8d164c7fc4eb2cd1d9
5
5
  SHA512:
6
- metadata.gz: a87675ed56dea1a9880a33761d8f40ead7b7385dc9e73be9dfd58467585551fcd081572d8b57ef8d51e51d94de2b824a1962923cce5041b0b5e110245e192359
7
- data.tar.gz: c16e472db1f8ab7a05d4ed7edfbd5a30450c1fe7e281c223484a33ac4e6f3141729807e9d11137377cbf61c537c632c41ec16f4fae5ae393b43cf8d718c71f17
6
+ metadata.gz: e514eb5aebbeb3082ad1bb3533943ae13643a428be6f71e1aea18c58929f52b2ba2f5a3ab52476a65dd16fdc135050ad4888dcd7c40a09225a2a7e7c47aaf626
7
+ data.tar.gz: 14f8a49fd277909205e4dcce3f7ff7bd122fbaf10f453e384cec619a8c5af5def9c5192429cf589c49dd3ea0059f5b2093a46a6b0b4810169fcd86a42191b165
data/.gitignore CHANGED
@@ -8,6 +8,7 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  *.bundle
11
+ *.gem
11
12
  *.so
12
13
  *.o
13
14
  *.a
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # PgBackup
2
2
 
3
- This gem adds rake tasks to your rails application for creating and restoring postgres dumps.
3
+ [![Gem Version](https://badge.fury.io/rb/pg_backup.svg)](http://badge.fury.io/rb/pg_backup)
4
+
5
+ This gem adds rake tasks to your rails application for creating and restoring postgres dumps. The dumps are created with ```pg_dump``` and restored with ```pg_restore``` - these tools are included in a full postgres installation, but also available as standalone binaries (needed if your db is not located in the application server).
4
6
 
5
7
  ## Requirements
6
8
  ```
@@ -24,7 +26,7 @@ And then execute:
24
26
 
25
27
  ```
26
28
  rake pg_backup:dump:create # create a dump from local db and save it locally
27
- rake pg_backup:dump:load # import latest dump from local file
29
+ rake pg_backup:dump:load # import latest dump from local file into local db
28
30
  ```
29
31
 
30
32
  ### Capistrano integration
@@ -36,10 +38,10 @@ require "pg_backup/integration/capistrano"
36
38
  ````
37
39
  this adds some capistrano tasks
38
40
  ```
39
- cap <env> pg_backup:dump:create # creates remote dump in remote dir
40
- cap <env> pg_backup:dump:load # imports latest remote dump in remote db
41
+ cap <env> pg_backup:dump:create # creates remote dump (from remote db) in remote dir
42
+ cap <env> pg_backup:dump:load # imports latest remote dump into remote db
41
43
  cap <env> pg_backup:dump:download # downloads latest remote dump to local dir
42
- cap <env> pg_backup:dump:upload # uploads to remote
44
+ cap <env> pg_backup:dump:upload # uploads latest local dump to remote dir
43
45
  ```
44
46
 
45
47
  ### deploy-mate integration
@@ -51,6 +53,11 @@ add to your ```Capfile```
51
53
  require "pg_backup/integration/deploy_mate"
52
54
  ```
53
55
 
56
+ ## ToDo
57
+ - allow change of dump dir (local and remote)
58
+ - tests? https://github.com/technicalpickles/capistrano-spec
59
+ - rotate local and remote dumps (keep last x dumps)
60
+
54
61
  ## Credits
55
62
  https://gist.github.com/hopsoft/56ba6f55fe48ad7f8b90
56
63
 
@@ -0,0 +1,20 @@
1
+ module PgBackup
2
+ module Helpers
3
+ module Database
4
+
5
+ def with_database_config
6
+ yield(
7
+ connection_config.fetch(:host, 'localhost'),
8
+ connection_config.fetch(:database),
9
+ connection_config.fetch(:username),
10
+ connection_config.fetch(:password)
11
+ )
12
+ end
13
+
14
+ def connection_config
15
+ ActiveRecord::Base.connection_config
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,6 @@
1
+ require "pg_backup/helpers/database"
2
+ include PgBackup::Helpers::Database
3
+
1
4
  namespace :pg_backup do
2
5
  namespace :dump do
3
6
 
@@ -6,7 +9,7 @@ namespace :pg_backup do
6
9
  file_name = Dir.glob("#{Rails.root}/dump/*.backup").sort.last
7
10
  fail "Can't find a dump file!" unless file_name
8
11
  puts "Loading dump file from #{file_name}..."
9
- with_config do |host, db, user, pw|
12
+ with_database_config do |host, db, user, pw|
10
13
  %x{ PGPASSWORD=#{pw} pg_restore --host #{host} --username #{user} --schema public --no-owner --no-acl --clean --dbname #{db} #{file_name} }
11
14
  end
12
15
  puts "Done."
@@ -16,8 +19,8 @@ namespace :pg_backup do
16
19
  task create: :environment do
17
20
  puts "Creating dump file..."
18
21
  FileUtils.mkdir_p Rails.root.join("dump")
19
- file_name = Rails.root.join("dump", "import-#{Time.now.to_i}.backup")
20
- with_config do |host, db, user, pw|
22
+ file_name = Rails.root.join("dump", "dump-#{Time.now.to_i}.backup")
23
+ with_database_config do |host, db, user, pw|
21
24
  %x{ PGPASSWORD=#{pw} pg_dump --host #{host} --username #{user} --clean --format=c --no-owner --no-acl #{db} > #{file_name} }
22
25
  end
23
26
  puts "Dump file located at #{file_name}."
@@ -27,10 +30,3 @@ namespace :pg_backup do
27
30
  end
28
31
  end
29
32
 
30
- def with_config
31
- yield connection_config.fetch(:host, 'localhost'), connection_config.fetch(:database), connection_config.fetch(:username), connection_config.fetch(:password)
32
- end
33
-
34
- def connection_config
35
- ActiveRecord::Base.connection_config
36
- end
@@ -1,3 +1,3 @@
1
1
  module PgBackup
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
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.1
4
+ version: 0.0.2
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-09-22 00:00:00.000000000 Z
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,7 @@ files:
66
66
  - README.md
67
67
  - Rakefile
68
68
  - lib/pg_backup.rb
69
+ - lib/pg_backup/helpers/database.rb
69
70
  - lib/pg_backup/integration/capistrano.rb
70
71
  - lib/pg_backup/integration/deploy_mate.rb
71
72
  - lib/pg_backup/railtie.rb
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  version: '0'
95
96
  requirements: []
96
97
  rubyforge_project:
97
- rubygems_version: 2.4.3
98
+ rubygems_version: 2.2.2
98
99
  signing_key:
99
100
  specification_version: 4
100
101
  summary: Create, restore, download and upload postgres dumps locally and on remote