Skip to content

Instantly share code, notes, and snippets.

@mru2
Forked from jgillman/restore.sh
Last active May 13, 2019 00:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mru2/e5cdc2ee1902d980d4d0df3b2d623a92 to your computer and use it in GitHub Desktop.
Save mru2/e5cdc2ee1902d980d4d0df3b2d623a92 to your computer and use it in GitHub Desktop.
pg_restore a local db dump into Docker
# Create and download backup
heroku pg:backups:capture
heroku pg:backups:download
# Assumes the database container is named 'db'
DOCKER_DB_NAME="$(docker-compose ps -q db)"
DB_HOSTNAME=db
DB_USER=postgres
LOCAL_DUMP_PATH="path/to/local.dump"
docker-compose up -d db
docker exec -i "${DOCKER_DB_NAME}" pg_restore -C --clean --no-acl --no-owner -U "${DB_USER}" -d "${DB_HOSTNAME}" < "${LOCAL_DUMP_PATH}"
docker-compose stop db
# Renaming seems not to work
psql> \c postgres
psql> drop database <original>
psql> alter database <new> rename to <original>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment