Mongodb backup and restore dockers

Create a container with data:

docker create -v /mongodb_data --name mongodb_data mongo 

Create a monogdb container:

 docker run --volumes-from mongodb_data --name mongo_db --restart always -d mongo 

Then, to use mongodb in my own container, I use the link command:

 --link mongo_db:mongo 

So everything is working fine. Now I want to backup mongodb according to the docs: http://docs.docker.com/userguide/dockervolumes/#backup-restore-or-migrate-data-volumes and this command:

 docker run --volumes-from mongodb_data -v $(pwd):/backup busybox tar cvf /backup/backup.tar /mongodb_data 

However, the created tar file only has an empty /mongodb_data folder. The folder contains more than one file.

Any ideas on something wrong? I am using docker 1.7 on ubuntu 14.04 LTS.

+7
docker mongodb
source share
2 answers

The problem is only in your data container. You make your volume using the /mongodb_data , which does not store mongo db data. By default, the mongo db storage path is /data/db (according to this #Where to Store Data Section)

As a result, your mongodb data is not stored in the data container. So here is a workaround:

  • copy /data/db to /mongodb_data in the mongodb docker exec -it mongo_db bash , then cp -r /data/db/* /mongodb_data/

  • backup by following the doc you were talking about

  • create a new data container and upload a backup

  • delete the current mongo_db container and create a new one with a container with new data

OR, you can change the mongodb configuration to change the default directory to /mongodb_data after copying all the data from /data/db to /mongodb_data . You can find this useful Changing the MongoDB Data Warehouse Directory

+4
source share

You can use this image , which provides a docker container for many tasks (import, export, dump)

0
source share

All Articles