Answer the question
In order to leave comments, you need to log in
How to implement a daily backup of a MongoDB database running in a docker container?
Hello. In my project on the MEAN stack, there is a Mongo database that is separately launched in a docker container
. An approximate container setup from a docker-compose file
mongodb:
image: mongo
ports:
- "27017:27017"
volumes:
- ./db:/data/db
networks:
- mean-network
mongodump --db dbName --out /data/db/backups/`date +"%m-%d-%y"`,
Answer the question
In order to leave comments, you need to log in
Alternatively, put something like this on cron:
docker run --rm --link {{your-mongo-container-name}}:mongo \
-v {{path_on_host & named volume}}:/data/db/backups/ \
mongo bash -c ‘mongodump --out /data/db/backups/`date +"%m-%d-%y"` --host mongo:27017’
I did something similar to the answer above. The cron runs `docker-compose up` which makes dumps. The main thing here is to get into the network you need, and contact the necessary host. If without certificates, then everything is simple.
networks:
production_default:
external: true
version: "3"
services:
mongodump:
image: mongo:4.0
volumes:
- ./mongodb/dump:/data/dump
command: /bin/sh -c 'mongodump --quiet --host mongodb --archive=/data/dump/$$(date +"%Y-%m-%d").gz --gzip --db databasename_production'
networks:
- production_default
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question