heroku_db_clone 0.9.0
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/bin/heroku-db-clone +5 -0
- data/heroku_db_clone.gemspec +21 -0
- data/lib/heroku_db_clone/client.rb +81 -0
- data/lib/heroku_db_clone/version.rb +3 -0
- data/lib/heroku_db_clone.rb +6 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Cameron Pope
|
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,42 @@
|
|
1
|
+
# heroku-db-clone
|
2
|
+
|
3
|
+
Backup a Heroku app's database and restore it locally. Defaults to
|
4
|
+
reading the 'development' section of `config/database.yml` to get
|
5
|
+
database configuration information.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'heroku_db_clone'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install heroku_db_clone
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
`heroku-db-clone [app-name]`
|
24
|
+
|
25
|
+
`heroku-db-clone --help` to get a list of options
|
26
|
+
|
27
|
+
## To Do
|
28
|
+
|
29
|
+
* Reasonable error messages if we cannot find required executables
|
30
|
+
|
31
|
+
* Specify username and password to postgres database if we cannot find
|
32
|
+
it
|
33
|
+
|
34
|
+
* Handle multi-file database dumps
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/heroku-db-clone
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'heroku_db_clone/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "heroku_db_clone"
|
8
|
+
gem.version = HerokuDbClone::VERSION
|
9
|
+
gem.authors = ["Cameron Pope"]
|
10
|
+
gem.email = ["cameron@theaboutbox.com"]
|
11
|
+
gem.description = %q{Performs a backup of a heroku database, downloads it, and installs it locally, using the information in your config/database.yml file}
|
12
|
+
gem.summary = %q{Clone a heroku app's database locally}
|
13
|
+
gem.homepage = ""
|
14
|
+
gem.executables << 'heroku-db-clone'
|
15
|
+
gem.add_dependency('trollop','~> 2.0.0')
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
|
3
|
+
module HerokuDbClone
|
4
|
+
class Client
|
5
|
+
def initialize
|
6
|
+
@opts = Trollop::options do
|
7
|
+
opt :capture, "Capture a fresh database backup", short: '-c'
|
8
|
+
opt :drop, "Drop the local database before importing the captured copy", short: '-d'
|
9
|
+
opt :keep, "Do not delete the downloaded backup file", short: '-k'
|
10
|
+
opt :verbose, "Verbose console output", short: '-v'
|
11
|
+
opt :dump_name, "Name of the dump to download", type: :string, default: 'db.dump'
|
12
|
+
end
|
13
|
+
|
14
|
+
@app_name = ARGV.shift
|
15
|
+
raise "Please specify a Heroku app name" if @app_name.nil?
|
16
|
+
|
17
|
+
load_db_information
|
18
|
+
|
19
|
+
log "Capturing Database for #{@app_name}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
capture if @opts[:capture]
|
24
|
+
download
|
25
|
+
drop if @opts[:drop]
|
26
|
+
import
|
27
|
+
clean_up unless @opts[:keep]
|
28
|
+
end
|
29
|
+
|
30
|
+
def capture
|
31
|
+
log "Capturing production database snapshot..."
|
32
|
+
exec "heroku pgbackups:capture --expire --app #{@app_name}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def download
|
36
|
+
log "Downloading snapshot..."
|
37
|
+
exec "curl -o #{@opts[:dump_name]} \`heroku pgbackups:url --app #{@app_name}\`"
|
38
|
+
end
|
39
|
+
|
40
|
+
def drop
|
41
|
+
log "Dropping Existing Database"
|
42
|
+
exec "dropdb #{@db_name}" rescue nil
|
43
|
+
exec "createdb -T template0 #{@db_name}" rescue nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def import
|
47
|
+
pg_cmd = []
|
48
|
+
pg_cmd << 'pg_restore --verbose --clean --no-acl --no-owner'
|
49
|
+
pg_cmd << "-h #{options[:host]}" if @db_host
|
50
|
+
pg_cmd << "-U #{options[:user]}" if @db_user
|
51
|
+
pg_cmd << "-d #{@db_name} #{@opts[:dump_name]}"
|
52
|
+
cmd = pg_cmd.join(' ')
|
53
|
+
exec cmd
|
54
|
+
end
|
55
|
+
|
56
|
+
def clean_up
|
57
|
+
exec "rm #{@opts[:dump_name]}"
|
58
|
+
end
|
59
|
+
|
60
|
+
# Internal: Prints an output message if the verbose option is true
|
61
|
+
def log(msg)
|
62
|
+
puts msg if @opts[:verbose]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Runs a command, outputting the command and output if verbose is true
|
66
|
+
def exec(cmd)
|
67
|
+
log cmd
|
68
|
+
log `#{cmd}`
|
69
|
+
end
|
70
|
+
|
71
|
+
# Internal: Get the configuration of the local development database
|
72
|
+
def load_db_information
|
73
|
+
raise "config/database.yml does not exist at the current location: #{File.expand_path('.')}" unless File.exists?('config/database.yml')
|
74
|
+
dev_db = YAML.load_file('config/database.yml')["development"]
|
75
|
+
@db_name = dev_db["database"]
|
76
|
+
@db_user = dev_db['username']
|
77
|
+
@db_password = dev_db['password']
|
78
|
+
@db_host = dev_db['host']
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku_db_clone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cameron Pope
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: trollop
|
16
|
+
prerelease: false
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.0
|
22
|
+
none: false
|
23
|
+
type: :runtime
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 2.0.0
|
29
|
+
none: false
|
30
|
+
description: Performs a backup of a heroku database, downloads it, and installs it
|
31
|
+
locally, using the information in your config/database.yml file
|
32
|
+
email:
|
33
|
+
- cameron@theaboutbox.com
|
34
|
+
executables:
|
35
|
+
- heroku-db-clone
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- .gitignore
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/heroku-db-clone
|
45
|
+
- heroku_db_clone.gemspec
|
46
|
+
- lib/heroku_db_clone.rb
|
47
|
+
- lib/heroku_db_clone/client.rb
|
48
|
+
- lib/heroku_db_clone/version.rb
|
49
|
+
homepage: ''
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
none: false
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
none: false
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.24
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Clone a heroku app's database locally
|
73
|
+
test_files: []
|