Skip to content

Mongodb backup instruction

Arooran Thanabalasingam edited this page Jan 3, 2022 · 2 revisions

Run inside same container

docker exec -i <CONTAINER> mongodump --db <DB> --gzip --archive > dump_$(date '+%d-%m-%Y_%H-%M-%S').gz
docker exec -i <CONTAINER> mongorestore --archive --gzip < dump.gz

Run separate docker container once

  • if mongodb runs inside a network, use the same network
  • use mongodb container name as hostname
  • with flag --rm, the container is destroyed after command is completed
docker run -i --network <NET> --rm mongo:4.4 mongodump --db <DB> --host <CONTAINER>:27017 --archive --gzip > dump_$(date '+%d-%m-%Y_%H-%M-%S').gz
  • using URI schema
docker run -i --rm mongo:4.4 mongodump --uri "mongodb+srv://foo:[email protected]/db-name" --archive --gzip > dump_$(date '+%d-%m-%Y_%H-%M-%S').gz
docker run -i --network <NET> --rm mongo:4.4 mongorestore --host <CONTAINER>:27017 --archive --gzip < dump.gz

transfer data using SSH

scp username@b:/path/origin/file /path/to/destination

based on

Clone this wiki locally