Last active
September 28, 2017 07:36
-
-
Save pharzan/b446a57d031935d8919ce610c1ff3aac to your computer and use it in GitHub Desktop.
Backup PostgreSQL database to a local file and retrieve it
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
# create a bakup: | |
sudo su - postgres | |
pg_dump postgres > postgres_db.bak | |
# options: | |
pg_dump -U user_name -h remote_host -p remote_port name_of_database > name_of_backup_file |
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
# Retrieve a backup | |
psql empty_database < backup_file | |
# Note: this redirection operation does not create the database in question. | |
# This must be done in a separate step prior to running the command. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment