0

I installed the mongo using the docker, Now I need to take the mongodb dump and restore.

1) where can I download these two tools?
2) I don't need to install the complete mongo since the mongo is already installed using docker, I just need to download these two mongo tools and use the IP and PORT of docker mongo to dump and restore.

Thanks,
Harry

Harry
  • 3,072
  • 6
  • 43
  • 100

1 Answers1

3

MongoDB install this tool beside the core database so you can just execute commands inside the container or install mongod in your system and use this you can use below command to get MongoDB data:

docker exec <CONTAINER> sh -c 'exec mongodump --db somedb --gzip --archive' > dump_`date "+%Y-%m-%d"`.gz

also, you can get these utilities without mongo core. here is an example package for alpine-linux: mongodb-tools. and for other distro you can make it yourself: mongodb-tools

amir
  • 2,443
  • 3
  • 22
  • 49
  • I agree that we can do using docker exec, but I need to connect to this docker from another machine, for this answer I provided an up vote – Harry Feb 03 '19 at 08:48
  • @Harry so why not bring up another machine with only utilities you need to get exported data? I mean create a new mongodb on docker and use it for just export and imports. – amir Feb 03 '19 at 08:50
  • thanks for your thought, but is there a way I get only the mongodump and mongorestore tools? So that i don't want to depend on docker in other machines – Harry Feb 03 '19 at 08:51
  • I will accept your answer, I have a clarification, How does the docker exec works for mongorestore ? docker exec f1d566 sh -c 'exec mongorestore --host 172.17.0.2 --port 27017 /home/test/mongo/dump_2019-02-03.gz' - This command is failing with the error : Failed: mongorestore target '/home/test/mongo/dump_2019-02-03.gz' invalid: stat /home/test/mongo/dump_2019-02-03.gz: no such file or directory – Harry Feb 03 '19 at 16:35