In the mongodb docker page there's the following tutorial on how to dump a mongodb collection:
sudo docker exec container_name sh -c 'exec mongodump -d collection_name --archive' > /home/mongo_backup/all-collections.archive
I thougth of creating another container which runs this dump periodically (twice a day for example) and saves to a folder that is mounted inside it. But can I mongodump from a container that is not the container that has the collections? Can I mongodump via local network?
After this is solved, there's still the problem of where to send this backup. It can't be on the same place as my code deployed because it can be erased accidentaly.
Is this a good backup strategy? Any better ideas?
I thougth of creating another container which runs this dump periodically [...] there's still the problem of where to send this backup
mgob - "MongoDB dockerized backup agent" does just that: it's a container running mongodump periodically with features to upload generated dump to various Clouds, S3 and SFTP.
We've been using it for some time both with Docker and Kubernetes with good results.
To Backup a MongoDB in the docker instance manually ( without creating another container )
You can do the following :
Backup MongoDB data
Login to the server ( if running locally you don't need this)
Run this command:
docker exec old-docker-mongodb-1 sh -c 'mongodump --archive' > db.dump
(This will create a db.dump file)
(replace old-docker-mongodb-1 with your docker container name)
Copy db.dump to your local ( you might not need this)
scp orginalpath/db.dump /d/mybackup
Restore mongoDB data to a docker continer
docker exec -i new-docker_mongodb_1 sh -c 'mongorestore --archive' < db.dump
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