Created
December 16, 2016 18:39
-
-
Save nathancolgate/2364f2132099c7168d7476667109370d to your computer and use it in GitHub Desktop.
Migrating postgres database from one server to another through tunnels
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
# Open SSH tunnels to both servers, routing postgres traffic to local port | |
# I use SSH Tunnel app for that, but I'm pretty sure you could figure out how to | |
# run that tunnel in the command line | |
# First: Dump the old DB | |
pg_dump -U deploy -h 127.0.0.1 -p 3303 -d my_app_production -F c -f outfile.sqlc | |
# It will prompt you for the user's password, and then you should be golden. | |
# -U username | |
# -h host (localhost) | |
# -p port (whatever port your ssh tunnel is running to) | |
# -d database (name of the remote database) | |
# -F format (c for custom) | |
# -f output file | |
# Last: Populate the new DB | |
pg_restore -U deploy -h 127.0.0.1 -p 3313 -d my_app_production -F c outfile.sqlc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment