Created
December 5, 2016 23:45
-
-
Save derencius/2d7e7147502b5e1a3f810c46f4d8da5f to your computer and use it in GitHub Desktop.
Heroku DB Download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requirement: your db name must have the same name as your app. (it does not have _development on the name) | |
save this script in a common folder outside your project. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "thor" | |
class MyCLI < Thor | |
desc "download", "production database" | |
def download(remote = 'production') | |
puts "Downloading... #{remote}" | |
system "heroku pg:backups capture --remote #{remote}" | |
system "curl `heroku pg:backups public-url --remote #{remote}` -o #{remote}.dump" | |
puts "Done!" | |
end | |
desc "restore", "load dump in dev database" | |
def restore(remote = 'production', db = Dir.pwd.split("/").last) | |
system "ps ax | grep postgres: | grep #{db} | cut -c1-8 | xargs kill" | |
system "dropdb #{db}; createdb #{db}" | |
system "pg_restore --verbose --clean --no-acl --no-owner -d #{db} #{remote}.dump" | |
system "touch tmp/restart.txt" | |
end | |
desc 'dr', 'download and restore' | |
def dr(remote = 'production') | |
download remote | |
restore remote | |
end | |
end | |
MyCLI.start(ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment