Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kamwing/5addddb554ecb20f86bfd0f34adc73de to your computer and use it in GitHub Desktop.
Save kamwing/5addddb554ecb20f86bfd0f34adc73de to your computer and use it in GitHub Desktop.

Backup and Restore Postgres databases

https://www.postgresqltutorial.com/postgresql-backup-database/

Backup a specific database use pg_dump

docker exec -t your-db-container pg_dump -U strapi -W -F t database-name > mypostgres_strapi_`date +%d-%m-%Y"_"%H_%M_%S`.sql

Backup all databases use pg_dumpall

docker exec -t your-db-container pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql

Access the database

docker exec -it ubuntu_postgres_1 psql -U strapi
docker exec -it ubuntu_postgres_1 psql -U strapi  postgres

List databases

\l

list tables

\dt

exit

\q

Drop table

docker exec -it ubuntu_postgres_1 dropdb -U strapi strapi

To Restore your databases

https://www.postgresqltutorial.com/postgresql-restore-database/

1.Create the database

docker exec -it ubuntu_postgres_1 createdb -U strapi strapi

2.Restore the backup

cat dump_strapidb.sql | docker exec -i ubuntu_postgres_1 psql -U strapi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment