简体   繁体   中英

How to backup MongoDB in a setup with multiple Docker containers?

I have an application which is split into multiple Docker containers:

  • Container 1 contains a MongoDB database
  • Container 2 contains a python script which performs some operations on a daily basis and stores the results in the MongoDB of Container 1 using pymongo.

Previously to using Docker, ie, having the MongoDB and the python app on the same machine, I could use mongoexport right after the daily scripts finished to backup my database. However, in the Docker setup, I can not use mongoexport in Container 2 because MongoDB is not installed, ie, the command is unknown.

From my point of view, the only option would be using a cronjob in Container 1 running a script which performs the backup on a preset time. However, I would prefer a solution in which Container 2 triggers the backup since the runtime of the daily scripts can vary considerably.

Thanks in advance for any suggestions!

You can download mongodb binaries on docker 2 form here . That way you can get rid of the command is unknown

You can export mongodb collection from mongodb running on container 1 using mongoexport or take dump using mongodump from container 2 using --host and --port options.

Note: mongoexport does not export indexes from collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM