Skip to content

Instantly share code, notes, and snippets.

@dtuite
Last active December 28, 2015 08:39
Show Gist options
  • Save dtuite/7473583 to your computer and use it in GitHub Desktop.
Save dtuite/7473583 to your computer and use it in GitHub Desktop.
Backup and Restore a PostgreSQL Database

PostgreSQL Backup and Restore

First, ssh into your server and run the following command to create a dump file.

pg_dump -U [DB_USER_NAME] [DB_NAME] -f [DUMP_FILE_NAME].sql

Next, copy the file to your local machine:

scp [SERVER_DEPLOYMENT_USER]@[SERVER_IP]:~/[PATH_TO_DUMP_FILE] ./

Restore:

psql -U [DB_USER_NAME] -d [DESTINATION_DB_NAME]-f [DUMP_FILE_NAME].sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment