pg_backup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f66072498adffba3bf660e3522330afd5e8b4060
4
+ data.tar.gz: 3827539bea4c8be2a97321d0e54cc9636fbc6fdf
5
+ SHA512:
6
+ metadata.gz: a87675ed56dea1a9880a33761d8f40ead7b7385dc9e73be9dfd58467585551fcd081572d8b57ef8d51e51d94de2b824a1962923cce5041b0b5e110245e192359
7
+ data.tar.gz: c16e472db1f8ab7a05d4ed7edfbd5a30450c1fe7e281c223484a33ac4e6f3141729807e9d11137377cbf61c537c632c41ec16f4fae5ae393b43cf8d718c71f17
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Marcus Geissler
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # PgBackup
2
+
3
+ This gem adds rake tasks to your rails application for creating and restoring postgres dumps.
4
+
5
+ ## Requirements
6
+ ```
7
+ rails
8
+ capistrano # optional
9
+ ```
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'pg_backup'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ 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
28
+ ```
29
+
30
+ ### Capistrano integration
31
+ (https://github.com/capistrano/capistrano)
32
+
33
+ add to your ```Capfile```
34
+ ```
35
+ require "pg_backup/integration/capistrano"
36
+ ````
37
+ this adds some capistrano tasks
38
+ ```
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:download # downloads latest remote dump to local dir
42
+ cap <env> pg_backup:dump:upload # uploads to remote
43
+ ```
44
+
45
+ ### deploy-mate integration
46
+ (https://github.com/hanseventures/deploy-mate)
47
+
48
+ add to your ```Capfile```
49
+
50
+ ```
51
+ require "pg_backup/integration/deploy_mate"
52
+ ```
53
+
54
+ ## Credits
55
+ https://gist.github.com/hopsoft/56ba6f55fe48ad7f8b90
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/[my-github-username]/pg_backup/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/capistrano.rake", __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/deploy_mate.rake", __FILE__)
@@ -0,0 +1,9 @@
1
+ module PgBackup
2
+ class Railtie < Rails::Railtie
3
+ railtie_name :pg_backup
4
+
5
+ rake_tasks do
6
+ load "pg_backup/tasks/dump.rake"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,67 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ # add the dump dir to the linked directories
4
+ set :linked_dirs, fetch(:linked_dirs, []).push('dump')
5
+ end
6
+ end
7
+
8
+ namespace :pg_backup do
9
+ namespace :dump do
10
+
11
+ desc "Loads the backup dump"
12
+ task :load do
13
+ on roles(:app) do
14
+ within current_path do
15
+ with rails_env: fetch(:environment) do
16
+ ask :answer, "Are you sure? This overwrites the '#{fetch(:environment)}' database! Type 'YES' if you want to continue..."
17
+ if fetch(:answer) == "YES"
18
+ rake "pg_backup:dump:load"
19
+ else
20
+ puts "Cancelled."
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ desc "Create remote db dump"
28
+ task :create do
29
+ on roles(:app) do
30
+ within current_path do
31
+ with rails_env: fetch(:environment) do
32
+ rake "pg_backup:dump:create"
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ desc "Upload latest db dump from (local) dump dir"
39
+ task :upload do
40
+ on roles(:app) do
41
+ within shared_path do
42
+ with rails_env: fetch(:environment) do
43
+ file_path = Dir.glob("#{ENV.fetch('PWD')}/dump/*.backup").last
44
+ fail "Can't find a dump file!" unless file_path
45
+ file_name = File.basename file_path
46
+ upload! file_path, "#{shared_path}/dump/#{file_name}"
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ desc "Download remote db dump"
53
+ task :download do
54
+ on roles(:app) do
55
+ within shared_path do
56
+ with rails_env: fetch(:environment) do
57
+ file_name = capture("ls -t #{shared_path}/dump | head -1")
58
+ # TODO: exit if there is no dump
59
+ # TODO: ensure dump dir
60
+ download! "#{shared_path}/dump/#{file_name}", "dump"
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,2 @@
1
+ before 'pg_backup:dump:create', 'rvm:hook'
2
+ before 'pg_backup:dump:load', 'rvm:hook'
@@ -0,0 +1,36 @@
1
+ namespace :pg_backup do
2
+ namespace :dump do
3
+
4
+ desc "Load dumped postgres backup file "
5
+ task load: :environment do
6
+ file_name = Dir.glob("#{Rails.root}/dump/*.backup").sort.last
7
+ fail "Can't find a dump file!" unless file_name
8
+ puts "Loading dump file from #{file_name}..."
9
+ with_config do |host, db, user, pw|
10
+ %x{ PGPASSWORD=#{pw} pg_restore --host #{host} --username #{user} --schema public --no-owner --no-acl --clean --dbname #{db} #{file_name} }
11
+ end
12
+ puts "Done."
13
+ end
14
+
15
+ desc "Create dump from postgres db"
16
+ task create: :environment do
17
+ puts "Creating dump file..."
18
+ 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|
21
+ %x{ PGPASSWORD=#{pw} pg_dump --host #{host} --username #{user} --clean --format=c --no-owner --no-acl #{db} > #{file_name} }
22
+ end
23
+ puts "Dump file located at #{file_name}."
24
+ puts "Done."
25
+ end
26
+
27
+ end
28
+ end
29
+
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
@@ -0,0 +1,3 @@
1
+ module PgBackup
2
+ VERSION = "0.0.1"
3
+ end
data/lib/pg_backup.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "pg_backup/version"
2
+
3
+ module PgBackup
4
+ require 'pg_backup/railtie' if defined?(Rails)
5
+ end
data/pg_backup.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pg_backup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pg_backup"
8
+ spec.version = PgBackup::VERSION
9
+ spec.authors = ["Marcus Geissler"]
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!}
13
+ spec.homepage = "https://github.com/marcusg/pg_backup"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "rails", ">= 3.0"
24
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pg_backup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marcus Geissler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Create, restore, download and upload postgres dumps locally and on remote
56
+ servers using capistrano. Really!
57
+ email:
58
+ - marcus3006@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/pg_backup.rb
69
+ - lib/pg_backup/integration/capistrano.rb
70
+ - lib/pg_backup/integration/deploy_mate.rb
71
+ - lib/pg_backup/railtie.rb
72
+ - lib/pg_backup/tasks/capistrano.rake
73
+ - lib/pg_backup/tasks/deploy_mate.rake
74
+ - lib/pg_backup/tasks/dump.rake
75
+ - lib/pg_backup/version.rb
76
+ - pg_backup.gemspec
77
+ homepage: https://github.com/marcusg/pg_backup
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Create, restore, download and upload postgres dumps locally and on remote
101
+ servers using capistrano.
102
+ test_files: []