Skip to content

Instantly share code, notes, and snippets.

@shawonis08
Last active February 17, 2023 15:41
Show Gist options
  • Save shawonis08/fb3cd0fafec39fa5061501b302022785 to your computer and use it in GitHub Desktop.
Save shawonis08/fb3cd0fafec39fa5061501b302022785 to your computer and use it in GitHub Desktop.
This document describes how to back up and restore a PostgreSQL database within a Docker container. The manual offers instructions for exporting and importing the database, as well as a link to a related Stack Overflow thread for further information.

Backup/restore a dockerized postgresql database

  • Export Database

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

cat your_dump.sql | docker exec -i your-db-container psql -U postgres

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment