Skip to content

Instantly share code, notes, and snippets.

@pharzan
Last active September 28, 2017 07:36
Show Gist options
  • Save pharzan/b446a57d031935d8919ce610c1ff3aac to your computer and use it in GitHub Desktop.
Save pharzan/b446a57d031935d8919ce610c1ff3aac to your computer and use it in GitHub Desktop.
Backup PostgreSQL database to a local file and retrieve it
# 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
# 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