Backup/Restore a dockerized PostgreSQL database

后端 未结 10 1823
[愿得一人]
[愿得一人] 2020-12-22 15:50

I\'m trying to backup/restore a PostgreSQL database as is explained on the Docker website, but the data is not restored.

The volumes used by the database image are:<

10条回答
  •  有刺的猬
    2020-12-22 16:01

    Backup Database

    generate sql:

    • docker exec -t your-db-container pg_dumpall -c -U your-db-user > dump_$(date +%Y-%m-%d_%H_%M_%S).sql

    to reduce the size of the sql you can generate a compress:

    • docker exec -t your-db-container pg_dumpall -c -U your-db-user | gzip > ./dump_$(date +"%Y-%m-%d_%H_%M_%S").gz

    Restore Database

    • cat your_dump.sql | docker exec -i your-db-container psql -U your-db-user -d your-db-name

    to restore a compressed sql:

    • gunzip < your_dump.sql.gz | docker exec -i your-db-container psql -U your-db-user -d your-db-name

    PD: this is a compilation of what worked for me, and what I got from here and elsewhere. I am beginning to make contributions, any feedback will be appreciated.

提交回复
热议问题