-
-
Save Rich86man/0aa8540e9b1d4fa58337 to your computer and use it in GitHub Desktop.
Import heroku database
This file contains 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 "Backs up heroku database and restores it locally" | |
task clong: :environment do | |
# Load the current environments database config | |
c = Rails.configuration.database_configuration[Rails.env] | |
# This gets around an issue with the Heroku Toolbelt | |
# https://github.com/sstephenson/rbenv/issues/400#issuecomment-18742700 | |
# https://github.com/sstephenson/rbenv/issues/400#issuecomment-18744931 | |
Bundler.with_clean_env do | |
# Capture new backup, delete oldest manual backup if limit reached | |
system("heroku pg:backups capture") | |
# Download the backup to a file called latest.dump, consider adding this file to .gitignore | |
system("curl -o latest.dump \`heroku pg:backups public-url\`") | |
# Restore the backup to the current environment's database | |
system("pg_restore --verbose --clean --no-acl --no-owner -h localhost -U #{c["username"]} -d #{c["database"]} latest.dump") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment