Backup/Restore a dockerized PostgreSQL database

后端 未结 10 1944
[愿得一人]
[愿得一人] 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'
    

提交回复
热议问题