Created
March 22, 2016 21:48
-
-
Save jmccartie/d0b58baebb39bf552b5b to your computer and use it in GitHub Desktop.
Copy Heroku production DB to local database
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
namespace :db do | |
desc "Copy production database to local" | |
task :copy_production => :environment do | |
### | |
# HEROKU | |
### | |
# Download latest dump | |
system("wget -O tmp/latest.dump `heroku pg:backups public-url -q`") | |
# get user and database name | |
config = Rails.configuration.database_configuration["development"] | |
database = config["database"] | |
user = config["username"] | |
# import | |
system("pg_restore --verbose --clean --no-acl --no-owner -h localhost -d #{database} #{Rails.root}/tmp/latest.dump") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment