0

I am trying to dump my mongodb, which is currently in a docker container on windows. I run the following command:

docker run --rm --link docker-mongodb_1:mongo --net docker_default -v /backup:/backup mongo bash -c "mongodump --out /backup/ --host mongo:27017"

The output is something like this (with no errors): "writing db.entity to " "done dumping db.entity"

However, I cannot find the actual dump. I have checked C:/backup, my local directory. Tried renaming the output and volumes, but with no luck. Does anyone know where the dump is stored?

  • I ended up connecting to the docker container directly, dumping it and then copying it. 1: `docker exec -it bash` 2:`mongodump --db ` 3:`exit` 4:`docker cp :/file/path/within/container /host/path/target` However, this does not explain why I cannot find the dump file from the above code. Any answers to this question are still welcome :) –  Jan 21 '18 at 17:40

1 Answers1

0

I have been trying to do the same. I have written a shell script which does this process of backing up the data as you require. You first need to run the container with a name (whatever you wish that container name to be)

BACKUP_DIR="/backup"
DB_CONTAINER_ID=$(docker ps -aqf "name=<**name of your container**>")
NETWORK_ID=$(docker inspect -f "{{ .NetworkSettings.Networks.root_default.NetworkID }}" $DB_CONTAINER_ID)

docker run -v $BACKUP_DIR:/backup --network $NETWORK_ID mongo:3.4 su -c "cd /backup && mongodump -h db -u <username> -p <password> --authenticationDatabase <db_name> --db <db_name>"

tar -zcvf $BACKUP_DIR/db.tgz $BACKUP_DIR/dump
rm -rf $BACKUP_DIR/dump
Arpit Goyal
  • 2,212
  • 11
  • 31