dev_dump 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02ea6b4294dfb088d43e62cbadb9ed2dae750475
4
+ data.tar.gz: 2e2aa9243d5e80cde9e6e7fb0a3d618dd5285ebd
5
+ SHA512:
6
+ metadata.gz: b7665a956a0fdf748611023c7904426c8409032af65872c9ee9a01c619e8299518c3317249b22fed2d777f48eb5927e8a6d1906397ac921874c8296aafc26d03
7
+ data.tar.gz: 0862212905543c781d19c2c68c38d8a3f7c22d421aedcfc6ee4dacd8a7d724f3fed10ce91f9b6bb22bdd59cd764bcdd6031ef4172aef4b856d8c09f108d35e23
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dev_dump.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andy Atkinson
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.
@@ -0,0 +1,31 @@
1
+ # DevDump
2
+
3
+ Provides Rake tasks to dump a database to an encrypted file on a remote server, download the file, and restore a local DB from the file.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dev_dump'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ This depends on `gpg`. Install it on OS X with `brew install gpg`.
16
+
17
+ ## Usage
18
+
19
+ rake dev_dump:dump # run from the app root on production. dump postgres DB to a file. supply a passphrase for gpg encryption.
20
+ rake dev_dump:download_file[/path/to/file/on/prod] # run from developer machine, with a file path in mind
21
+ rake dev_dump:load[/path/to/local/file] # run after the dump file is downloaded
22
+
23
+ ## Configuration
24
+
25
+ Configuration can be provided with a Rails initializer as a configuration file, following [this approach](http://robots.thoughtbot.com/mygem-configure-block).
26
+
27
+ DevDump.configure do |config|
28
+ config.backups_path = "/tmp/some_dir"
29
+ config.ssh_user = "user"
30
+ config.ssh_host = "host.server.com"
31
+ end
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dev_dump/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dev_dump"
8
+ spec.version = DevDump::VERSION
9
+ spec.authors = ["Andy Atkinson"]
10
+ spec.email = ["andyatkinson@gmail.com"]
11
+ spec.summary = %q{Rake tasks to work with a remote database.}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,24 @@
1
+ require "dev_dump/version"
2
+ require "dev_dump/railtie" if defined?(Rails)
3
+
4
+ module DevDump
5
+ class << self
6
+ attr_accessor :configuration
7
+ end
8
+
9
+ def self.configure
10
+ self.configuration ||= Configuration.new
11
+ yield(configuration)
12
+ end
13
+
14
+ class Configuration
15
+ attr_accessor :rails_db_config, :backups_path, :ssh_user, :ssh_host
16
+
17
+ def initialize
18
+ self.rails_db_config = YAML.load_file(File.join(Dir.getwd, 'config', 'database.yml'))[Rails.env]
19
+ self.backups_path = "/tmp/backups/"
20
+ self.ssh_user = nil
21
+ self.ssh_host = nil
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'dev_dump'
2
+ require 'rails'
3
+ require 'rails/railtie'
4
+
5
+ module DevDump
6
+ class Railtie < Rails::Railtie
7
+ rake_tasks do
8
+ # NOTE: seems like it should be able to be called from config.after_initialize block, but that didn't work
9
+ require Rails.root.join('config/initializers/dev_dump.rb')
10
+
11
+ load 'tasks/dev_dump.rake'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module DevDump
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,66 @@
1
+ require "yaml"
2
+ require "erb"
3
+ require "dev_dump"
4
+ include DevDump
5
+
6
+ namespace :dev_dump do
7
+ desc "dump the database to a zipped file"
8
+ task :dump => :environment do
9
+ raise "gpg is required." unless `which gpg`
10
+ raise "Ruby on Rails is required." unless defined?(Rails)
11
+ raise "pg_dump is required." unless `which pg_dump`
12
+
13
+ if db_config = DevDump.configuration.rails_db_config
14
+ filename = "#{db_config['database']}.dump.#{Time.now.to_i}.sql"
15
+ Dir.mkdir(DevDump.configuration.backups_path) unless File.exists?(DevDump.configuration.backups_path)
16
+ file = "#{DevDump.configuration.backups_path}#{filename}"
17
+ db_user = ERB.new(db_config['username']).result
18
+
19
+ `pg_dump --clean --no-owner --no-privileges -U#{db_user} #{db_config['database']} | gzip > #{file}.gz`
20
+ if File.exists?("#{file}.gz")
21
+ `gpg -c #{file}.gz`
22
+ `rm #{file}.gz`
23
+ puts "wrote file: #{file}.gz.gpg"
24
+ end
25
+ end
26
+ end
27
+
28
+ desc "download dump file"
29
+ task :download_file, [:remote_path] do |t, args|
30
+ if args && args[:remote_path]
31
+ command = "scp #{DevDump.configuration.ssh_user}@#{DevDump.configuration.ssh_host}:#{args[:remote_path]} #{args[:remote_path]}"
32
+ puts "downloading file with command: #{command}"
33
+ `#{command}`
34
+ puts "done."
35
+ end
36
+ end
37
+
38
+ desc "load the database from a zipped file"
39
+ task :load, [:filepath] do |t, args|
40
+ raise "gpg is required." unless `which gpg`
41
+ raise "gunzip is required." unless `which gunzip`
42
+ raise "psql is required." unless `which psql`
43
+
44
+ file = if args.present? && File.exists?(args[:filepath])
45
+ args[:filepath]
46
+ else
47
+ `ls -tr #{DevDump.configuration.backups_path} | tail -n1`.chomp
48
+ end
49
+ if file.empty?
50
+ puts "no backups found"
51
+ else
52
+ puts "restoring from file: #{file}"
53
+ if db_config = DevDump.configuration.rails_db_config
54
+ db_user = ERB.new(db_config['username']).result
55
+ gzipped_file = file.gsub(/\.gpg/, '')
56
+ puts "gzipped file path: #{gzipped_file}"
57
+
58
+ `gpg #{file}`
59
+ if File.exists?(gzipped_file)
60
+ `gunzip -c #{gzipped_file} | psql -U #{db_user} -d #{db_config['database']}`
61
+ end
62
+ puts "...done."
63
+ end
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dev_dump
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andy Atkinson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-26 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ''
42
+ email:
43
+ - andyatkinson@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - dev_dump.gemspec
54
+ - lib/dev_dump.rb
55
+ - lib/dev_dump/railtie.rb
56
+ - lib/dev_dump/version.rb
57
+ - lib/tasks/dev_dump.rake
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.14
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Rake tasks to work with a remote database.
82
+ test_files: []
83
+ has_rdoc: