I want to come back on this dump and restore relstorage in cookieplone created docker-swarm challenge
This is not a backup replacement! but can be used for quick restore in uncritical development situations:
- Dump the Postgres database out of the container using the pg_dump command into a single file including blobs.
- Reimport the dump into a staging server instance with an exact matching setup (no filestorage, Postgres relstorage)
Create the dump
For a cookieplone 0.9.3 and template 83b50c6 based basic devops setup for a Plone 6.1.1 using docker swarm I this command dumps the PostgreSQL database into the user root directory:
From my inspirational source:
Since you are not able to provide a password directly through arguments, we rely on the
PGPASSWORDenvironment variable
mkdir /root/psql-dump
docker exec -i `docker ps -qf 'name=_db'|head -n1` /bin/bash \
-c "PGPASSWORD=pg_password pg_dump --username=plone --dbname=plone" \
> /root/psql-dump/project-title-psqldump-`date +%Y%m%d_%H%M%S`.sql
NOTE: The initial part picks the postgres container estimating the name contains
_db
Import the dump (not tested yet)
I expect you need to
- shut down the backend
- replace the database
- restart the backend
THIS IS THE OPEN QUESTION -> Backend Start Stop in Dockerized Production is Unclear
I have not found a proper description / procedure for the devops setup how to temporarily shut down a dockerized production system and restart only on demand after restoring the database.
The system setup is designed to restart at once if a container wents down.
Import / Restore dump command
The command to replace the database in the Postgres container should be similarily working
Prerequisite:
- The site should be provisoned with identical setup except the FQDN and be working with the default setup.
- Since both setups are identical they should share database name an credentials
- The path to the dump file should also be the same for loading
docker exec -i `docker ps -qf 'name=_db'|head -n1` /bin/bash \
-c "PGPASSWORD=pg_password psql --username=plone --dbname=plone" \
< /root/psql-dump/project-title-psqldump-[datetime].sql
IMPORTANT
- Maybe a wipe database option is missing in the example command above.
- There is also a
pg_restorecommandI am focusing the start and stop challenge for now.
DO NOT test this import example on a production site!