Skip to content

Instantly share code, notes, and snippets.

@ajepe
Forked from wikiti/bash.sh
Last active December 25, 2022 05:59
Show Gist options
  • Save ajepe/987deaeb24d76e83120c63d2e5121ed1 to your computer and use it in GitHub Desktop.
Save ajepe/987deaeb24d76e83120c63d2e5121ed1 to your computer and use it in GitHub Desktop.
Backup and restore in PostgreSQL using compressed backups.
# List databases
sudo su postgres
psql
\list
# Create a compressed backup
sudo su postgres
pg_dump -Fc <database_name> > <file>
# Example
pg_dump -Fc geartranslations_development > /tmp/backup.dump
# Restore a plain-text backup
# TABLES THAT ALREADY EXIST WILL NOT BE MODIFIED.
sudo su postgres
pg_restore -Fc -d <database_name> <backup_file>
# Example
pg_restore -Fc -d geartranslations_development /tmp/backup.dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment