Last active
March 17, 2022 04:51
-
-
Save zflat/5988612 to your computer and use it in GitHub Desktop.
Migrate pg dump from Heroku to local sqlite3 development (and beyond)
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
# Export the Heroku PG database to a local dump file | |
# https://devcenter.heroku.com/articles/heroku-postgres-import-export#export | |
heroku pgbackups:capture | |
curl -o latest.dump `heroku pgbackups:url` | |
# Install postregs & Setup password | |
# https://help.ubuntu.com/community/PostgreSQL | |
# List databases | |
sudo -u postgres psql -l | |
# Create database for data | |
# http://www.commandprompt.com/ppbook/x17149 | |
sudo -u postgres psql template1 | |
template1=# CREATE DATABASE bikedb | |
# or | |
sudo -u postgres createdb bikedb | |
# Run restore script with options | |
# http://antonzolotov.com/2012/03/04/rails-scripts-clone-heroku-database-to-development.html | |
sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -d bikedb latest.dump | |
# Dump the data (only, not structure) from postgres to normal SQL | |
# https://yuji.wordpress.com/2011/05/25/postgresql-sqlite-django-migrating-postgresql-to-sqlite3-with-pg_dump/ | |
# http://www.linuxtopia.org/online_books/database_guides/Practical_PostgreSQL_database/PostgreSQL_x17860_001.htm | |
sudo -u postgres pg_dump --inserts -a -b bikedb > data.sql | |
# Clear all data from the development database | |
bundle exec rake db:drop | |
bundle exec rake db:schema:load | |
# Read data into development database | |
# https://yuji.wordpress.com/2011/05/25/postgresql-sqlite-django-migrating-postgresql-to-sqlite3-with-pg_dump/ | |
sqlite3 development.sqlite3 | |
> .read data.sql | |
# Additional import-export | |
# Use taps gem | |
# https://rubygems.org/gems/taps-taps/versions/0.3.24 | |
# https://github.com/wijet/taps |
Is this still working in 2018?
Created a gist based from this one and other sources:
https://gist.github.com/jeffreycastro/918a24588ac1628e2af6b0def5bb7416
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure if something has changed since you wrote this, but I got the following error from the Heroku command (on Ubuntu)
▸ pgbackups:capture is not a heroku command.
▸ Perhaps you meant pg:backups:capture?