Skip to content

Instantly share code, notes, and snippets.

@litnimax
Created December 26, 2017 15:57
Show Gist options
  • Select an option

  • Save litnimax/814b9e2b81541cbf704be3c6c29a71a3 to your computer and use it in GitHub Desktop.

Select an option

Save litnimax/814b9e2b81541cbf704be3c6c29a71a3 to your computer and use it in GitHub Desktop.
rds_to_docker.md

Make a backup from RDS

pg_dump -h <rds host> -p 5432 -F c -O -U <rds user> <db name> > db.dump

Restore the backup into a Docker container

docker run --rm --interactive --link <postgres container id>:postgres --volume $PWD/:/tmp/ postgres:latest /bin/bash -c 'pg_restore --verbose --clean --no-acl --no-owner -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres -d <db name> /tmp/db.dump'

Access the db interactively

docker run --rm --interactive --tty --link <postgres container id>:postgres --volume $PWD/:/tmp/ postgres:latest /bin/bash -c 'psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres -d <db name>'

Make a backup of a dockerized postgres

docker run --rm --interactive --link <postgres container id>:postgres --volume $PWD/:/tmp/ postgres:latest /bin/bash -c 'pg_dump -h "$POSTGRES_PORT_5432_TCP_ADDR" -p $POSTGRES_PORT_5432_TCP_PORT -F c -O -U postgres <db name> > /tmp/db.dump'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment