pg_backup 0.0.3 → 0.1.0

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: aae918d69fa35757f12220b03705420527a1e116
4
- data.tar.gz: ba1e0cc7aafb5fbc540c732d05ff889cd2f80906
3
+ metadata.gz: 5f136aa92d7f7ae460ae869254a87aeecc78e2a1
4
+ data.tar.gz: 089fcf1e73498e09a038ea01bb2400764709854e
5
5
  SHA512:
6
- metadata.gz: c67efdac865ea88bb4b36bfd9fad2ad098864b82d354ed7ed586dad80aaf9017a5e1659f6b307580b96960b8d4c2b5b00d9b961a29cc50ad6143268f9819318e
7
- data.tar.gz: 13cd2f6e0a3477cd4c8a205f3301e235d19add91fa0ef9c7109cd4a76d0565713422582eb12846191c81602f6b5b5e03cd1cf131a33018e8e2196903cf936f1f
6
+ metadata.gz: afbf6f81d1d0c1139fd06032503a7992611f173b48b77396808902e6a45445253c5ddd21c07859aa4cde5310285d78d6bff445f397c371ae0543a3d5b5fb3eb5
7
+ data.tar.gz: 854b45c9fe20e088cd0a0a9d613e69eeeb512f68d26288469272d74f1c87fd249bc8ab388ceaf8ad2cf529ee9c36f96a78bd08e453d87076d27255bb6765cef7
data/.rubocop.yml ADDED
@@ -0,0 +1,33 @@
1
+ Style/Encoding:
2
+ Enabled: false
3
+
4
+ Style/Alias:
5
+ Enabled: false
6
+
7
+ Documentation:
8
+ Enabled: false
9
+
10
+ ClassAndModuleChildren:
11
+ Enabled: false
12
+
13
+ Metrics/LineLength:
14
+ Max: 500
15
+
16
+ Metrics/AbcSize:
17
+ Max: 25
18
+
19
+ Metrics/MethodLength:
20
+ Max: 15
21
+
22
+ Metrics/ClassLength:
23
+ Max: 200
24
+
25
+ StringLiterals:
26
+ Enabled: false
27
+
28
+ AllCops:
29
+ TargetRubyVersion: 2.2
30
+ Exclude:
31
+ - db/schema.rb
32
+ - bin/*
33
+ - db/migrate/*
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # PgBackup
2
2
 
3
+ ## create and restore postgres dumps with capistrano
4
+
3
5
  [![Gem Version](https://badge.fury.io/rb/pg_backup.svg)](http://badge.fury.io/rb/pg_backup)
4
6
 
5
7
  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).
@@ -31,8 +33,8 @@ rake pg_backup:dump:load # import latest dump from local file into local db
31
33
 
32
34
  If you want to create or load a dump file from a different directory, use the ``` DUMP_DIR ``` env var:
33
35
  ```
34
- rake DUMP_DIR=my_dump_dir pg_backup:dump:create
35
- rake DUMP_DIR=my_dump_dir pg_backup:dump:load
36
+ rake DUMP_DIR=/my/dump/dir pg_backup:dump:create
37
+ rake DUMP_DIR=/my/dump/dir pg_backup:dump:load
36
38
  ```
37
39
 
38
40
  ### Capistrano integration
@@ -52,8 +54,8 @@ cap <env> pg_backup:dump:upload # uploads latest local dump to remote dir
52
54
 
53
55
  To overwrite dump directories in capistrano, place something like this in your deploy.rb or \<stage\>.rb
54
56
  ```
55
- set :pg_backup_local_dump_dir, 'my_dump_dir'
56
- set :pg_backup_remote_dump_dir, 'my_dump_dir'
57
+ set :pg_backup_local_dump_dir, '/my/dump/dir'
58
+ set :pg_backup_remote_dump_dir, '/my/dump/dir'
57
59
  ```
58
60
 
59
61
  ### deploy-mate integration
@@ -65,16 +67,12 @@ add to your ```Capfile```
65
67
  require "pg_backup/integration/deploy_mate"
66
68
  ```
67
69
 
68
- ## ToDo
69
- - tests? https://github.com/technicalpickles/capistrano-spec
70
- - rotate local and remote dumps (keep last x dumps)
71
-
72
70
  ## Credits
73
71
  https://gist.github.com/hopsoft/56ba6f55fe48ad7f8b90
74
72
 
75
73
  ## Contributing
76
74
 
77
- 1. Fork it ( https://github.com/[my-github-username]/pg_backup/fork )
75
+ 1. Fork it ( https://github.com/marcusg/pg_backup/fork )
78
76
  2. Create your feature branch (`git checkout -b my-new-feature`)
79
77
  3. Commit your changes (`git commit -am 'Add some feature'`)
80
78
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,2 +1 @@
1
1
  require "bundler/gem_tasks"
2
-
@@ -1,7 +1,6 @@
1
1
  module PgBackup
2
2
  module Helpers
3
3
  module Database
4
-
5
4
  def with_database_config
6
5
  yield(
7
6
  connection_config.fetch(:host, 'localhost'),
@@ -14,7 +13,6 @@ module PgBackup
14
13
  def connection_config
15
14
  ActiveRecord::Base.connection_config
16
15
  end
17
-
18
16
  end
19
17
  end
20
18
  end
@@ -10,7 +10,6 @@ end
10
10
 
11
11
  namespace :pg_backup do
12
12
  namespace :dump do
13
-
14
13
  desc "Loads the backup dump"
15
14
  task :load do
16
15
  on roles(:app) do
@@ -44,7 +43,7 @@ namespace :pg_backup do
44
43
  within current_path do
45
44
  with rails_env: fetch(:environment) do
46
45
  file_path = Dir.glob("#{ENV.fetch('PWD')}/#{fetch(:pg_backup_local_dump_dir)}/*.backup").last
47
- fail "Can't find a dump file!" unless file_path
46
+ raise "Can't find a dump file!" unless file_path
48
47
  file_name = File.basename file_path
49
48
  upload! file_path, "#{shared_path}/#{fetch(:pg_backup_remote_dump_dir)}/#{file_name}"
50
49
  end
@@ -54,17 +53,23 @@ namespace :pg_backup do
54
53
 
55
54
  desc "Download remote db dump"
56
55
  task :download do
56
+ run_locally { FileUtils.mkdir_p fetch(:pg_backup_local_dump_dir).to_s }
57
57
  on roles(:app) do
58
58
  within current_path do
59
59
  with rails_env: fetch(:environment) do
60
- file_name = capture("ls -t #{shared_path}/#{fetch(:pg_backup_remote_dump_dir)} | head -1")
61
- # TODO: exit if there is no dump
62
- # TODO: ensure dump dir
63
- download! "#{shared_path}/#{fetch(:pg_backup_remote_dump_dir)}/#{file_name}", "#{fetch(:pg_backup_local_dump_dir)}"
60
+ if !test("[ -d #{shared_path}/#{fetch(:pg_backup_remote_dump_dir)} ]")
61
+ error "Folder '#{shared_path}/#{fetch(:pg_backup_remote_dump_dir)}' does not exits!"
62
+ else
63
+ file_name = capture("ls -t #{shared_path}/#{fetch(:pg_backup_remote_dump_dir)} | head -1")
64
+ if file_name.empty?
65
+ error "No dump file found in '#{shared_path}/#{fetch(:pg_backup_remote_dump_dir)}'!"
66
+ else
67
+ download! "#{shared_path}/#{fetch(:pg_backup_remote_dump_dir)}/#{file_name}", fetch(:pg_backup_local_dump_dir).to_s
68
+ end
69
+ end
64
70
  end
65
71
  end
66
72
  end
67
73
  end
68
-
69
74
  end
70
75
  end
@@ -3,14 +3,13 @@ include PgBackup::Helpers::Database
3
3
 
4
4
  namespace :pg_backup do
5
5
  namespace :dump do
6
-
7
- desc "Load dumped postgres backup file "
6
+ desc "Load dumped postgres backup file"
8
7
  task load: :environment do
9
8
  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
9
+ raise "[pg_backup:dump:load] Can't find a dump file!" unless file_name
11
10
  say "[pg_backup:dump:load] Loading dump file from #{file_name}..."
12
11
  with_database_config do |host, db, user, pw|
13
- %x{ PGPASSWORD=#{pw} pg_restore --host #{host} --username #{user} --schema public --no-owner --no-acl --clean --dbname #{db} #{file_name} }
12
+ ` PGPASSWORD=#{pw} pg_restore --host #{host} --username #{user} --schema public --no-owner --no-acl --clean --dbname #{db} #{file_name} `
14
13
  end
15
14
  say "[pg_backup:dump:load] Done."
16
15
  end
@@ -19,9 +18,9 @@ namespace :pg_backup do
19
18
  task create: :environment do
20
19
  say "[pg_backup:dump:create] Creating dump file..."
21
20
  FileUtils.mkdir_p Rails.root.join(dump_dir)
22
- file_name = Rails.root.join(dump_dir, "dump-#{Time.now.to_i}.backup")
21
+ file_name = Rails.root.join(dump_dir, "dump-#{Time.now.strftime('%Y%m%d%H%M%S')}.backup")
23
22
  with_database_config do |host, db, user, pw|
24
- %x{ PGPASSWORD=#{pw} pg_dump --host #{host} --username #{user} --clean --format=c --no-owner --no-acl #{db} > #{file_name} }
23
+ ` PGPASSWORD=#{pw} pg_dump --host #{host} --username #{user} --clean --format=c --no-owner --no-acl #{db} > #{file_name} `
25
24
  end
26
25
  say "[pg_backup:dump:create] New dump file located at #{file_name}."
27
26
  say "[pg_backup:dump:create] Done."
@@ -34,7 +33,5 @@ namespace :pg_backup do
34
33
  def say(text)
35
34
  respond_to?(:info) ? info(text) : puts(text)
36
35
  end
37
-
38
36
  end
39
37
  end
40
-
@@ -1,3 +1,3 @@
1
1
  module PgBackup
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0".freeze
3
3
  end
data/pg_backup.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = PgBackup::VERSION
9
9
  spec.authors = ["Marcus Geissler"]
10
10
  spec.email = ["marcus3006@gmail.com"]
11
- spec.summary = %q{Create, restore, download and upload postgres dumps locally and on remote servers using capistrano.}
12
- spec.description = %q{Create, restore, download and upload postgres dumps locally and on remote servers using capistrano. Really!}
11
+ spec.summary = 'Create, restore, download and upload postgres dumps locally and on remote servers using capistrano.'
12
+ spec.description = 'Create, restore, download and upload postgres dumps locally and on remote servers using capistrano. Really!'
13
13
  spec.homepage = "https://github.com/marcusg/pg_backup"
14
14
  spec.license = "MIT"
15
15
 
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.3
4
+ version: 0.1.0
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-11-19 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,7 @@ extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
+ - ".rubocop.yml"
64
65
  - Gemfile
65
66
  - LICENSE.txt
66
67
  - README.md
@@ -95,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  version: '0'
96
97
  requirements: []
97
98
  rubyforge_project:
98
- rubygems_version: 2.4.3
99
+ rubygems_version: 2.4.5.1
99
100
  signing_key:
100
101
  specification_version: 4
101
102
  summary: Create, restore, download and upload postgres dumps locally and on remote