I'm trying to setup docker-compose with Node and MongoDB. In combination with the official Mongo container I'm using a dedicated container (mongodb-backup) for continuous backups of the database and an initial restore at startup.
My problem is how to trigger a backup in case of a graceful shutdown by docker-compose stop
.
Therefore it's necessary to shut down the Node container at first to guarantee no process is writing to the database. Then backup the database and finally shutdown the mongodb and mongodb-backup conatainers.
This repository contains my docker-compose setup of mongodb and mongodb-backup.
Does anyone have an idea how to implement this?
You could write a small maintenance script for this case. Instead of doing a raw docker-compose stop
, you could just run this script instead. Let's call it maintenance.sh:
#!/bin/sh
docker-compose stop app
docker-compose stop mongo-backup # ensure only one is active
docker-compose run --rm -e INIT_BACKUP=1 # do the backup manually
docker-compose stop mongo # stop the database
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With