Backup/Restore a dockerized PostgreSQL database

后端 未结 10 1822
[愿得一人]
[愿得一人] 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:15

    Another approach (based on docker-postgresql-workflow)

    Local running database (not in docker, but same approach would work) to export:

    pg_dump -F c -h localhost mydb -U postgres export.dmp
    

    Container database to import:

    docker run -d -v /local/path/to/postgres:/var/lib/postgresql/data postgres #ex runs container as `CONTAINERNAME` #find via `docker ps`
    docker run -it --link CONTAINERNAME:postgres  --volume $PWD/:/tmp/  postgres  bash -c 'exec pg_restore -h postgres -U postgres -d mydb -F c /tmp/sonar.dmp'
    
    0 讨论(0)
  • 2020-12-22 16:16

    Backup your databases

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

    Restore your databases

    cat your_dump.sql | docker exec -i your-db-container psql -U postgres
    
    0 讨论(0)
  • 2020-12-22 16:21

    The below command can be used to take dump from docker postgress container

    docker exec -t <postgres-container-name> pg_dump --no-owner -U <db-username> <db-name> > file-name-to-backup-to.sql
    
    0 讨论(0)
  • 2020-12-22 16:25

    dksnap (https://github.com/kelda/dksnap) automates the process of running pg_dumpall and loading the dump via /docker-entrypoint-initdb.d.

    It shows you a list of running containers, and you pick which one you want to backup. The resulting artifact is a regular Docker image, so you can then docker run it, or share it by pushing it to a Docker registry.

    (disclaimer: I'm a maintainer on the project)

    0 讨论(0)
提交回复
热议问题