- Ensure that a shared folder exists between the containers. For example, I have the following volume mapping on both instances:
- ./backups:/backups
- Create a backup via the command
pg_dump
. For example, the following docker containermyapp_db_1
:
-
docker exec myapp_db_1 bash -c "pg_dump --username=myuser --no-password --format=c mydatabase > /backups/1.dump"
- Restore via the command
pg_restore
on another (newer major) of postgres:
-
docker exec myapp_db_2 bash -c "pg_restore --username=myuser --no-password --dbname=mydatabase --verbose /backups/1.dump"