I’m currently working on restoring backups in a containerized MongoDB environment. The issue I’m facing is that when I initiate the restore process, it starts, but after running the describe restore
command, the status shows as either running or down. The process gets stuck while attempting to stop mongod
, which causes the container to shut down and the pbm-agent
to fail. Additionally, PBM does not trigger the container to restart, so the restore never completes. Is there an alternative method to perform restores in a containerized MongoDB setup?
Hi @vishnu ,
I just found this topic that was not answered. Are you still experiencing this issue?
The core of the solution is to prevent the container from exiting when mongod
it stops.
For physical backups, make sure to use a container that includes both the mongod
binary as well as the PBM files. Here is an example Dockerfile:
FROM percona/percona-server-mongodb:latest AS mdb
FROM percona/percona-backup-mongodb:latest AS pbm
FROM oraclelinux:8
RUN mkdir -p /data/db /data/configdb
COPY --from=mdb /usr/bin/mongod /usr/bin/
COPY --from=pbm /usr/bin/pbm* /usr/bin/
If you are using a dedicated container for PBM, it should also have read-write access to MongoDB data volume and you should run it under the same user ID as the MongoDB container.
The other solution (might be complementary) is to use an “init system” that runs as PID 1, launches mongod
as a child process, and reaps any zombie processes. When mongod
is stopped, the init system remains running, keeping the container alive for the pbm-agent
to complete its work. Most official Docker images (including newer MongoDB images) now bundle tini
. You can enable it with a simple flag:
services:
mongo:
image: mongo:6.0
# Add this line to use tini as the init process
init: true
...
and in the Dockerfile:
# Install tini
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
# ... add your pbm-agent setup here ...
# The ENTRYPOINT becomes tini, which then executes your command
ENTRYPOINT ["/tini", "--"]
Alternatively, if that’s an option, switch to the Kubernetes platform and use our operator that will make things simpler for you.
Hi @radoslaw.szulgo
I followed the method you suggested, but it didn’t work. While I’m able to perform physical and incremental backups, I’m unable to restore them. Is there any alternative approach to restore other than using init
?
Hi vishnu, first of all the containers need to run with restart=no. Otherwise the restore won’t be able to complete. It is your responsibility to restart containers after the restore is complete. See Run in Docker - Percona Backup for MongoDB for more details about running in Docker.
During physical restore it is expected that the agent commands will not work as usual, you can uses the configuration file to read the restore status directly from the storage. See View restore progress - Percona Backup for MongoDB for more details.