To take backup of all databases in mongodb
List all databases;
show dbs; admin 0.000GB local 0.000GB twitter 0.720GB viva 0.061GB
1. DUMP ALL THE DATABASES IN MongoDB
Default dump location is : /dump
SYNTAX :
mongodump -h <hostname>
sachin@sachin-Inspiron-15-3567:~/dump$ mongodump -h localhost 2017-12-03T00:04:44.665+0530 writing admin.system.version to 2017-12-03T00:04:44.667+0530 done dumping admin.system.version (1 document) 2017-12-03T00:04:44.668+0530 writing twitter.kashmir to 2017-12-03T00:04:44.668+0530 writing twitter.total to 2017-12-03T00:04:44.668+0530 writing twitter.repo to 2017-12-03T00:04:44.668+0530 writing twitter.northkorea to 2017-12-03T00:04:44.832+0530 done dumping twitter.total (35927 documents) 2017-12-03T00:04:44.832+0530 writing twitter.twitte2 to 2017-12-03T00:04:46.020+0530 done dumping twitter.repo (35927 documents) 2017-12-03T00:04:46.020+0530 writing viva.external to 2017-12-03T00:04:47.006+0530 done dumping twitter.twitte2 (35922 documents) 2017-12-03T00:04:47.006+0530 writing twitter.sahpur to 2017-12-03T00:04:47.645+0530 [######..................] twitter.kashmir 54868/210000 (26.1%) 2017-12-03T00:04:47.645+0530 [#########...............] twitter.northkorea 46152/116954 (39.5%) 2017-12-03T00:04:47.645+0530 [#########...............] viva.external 14022/35922 (39.0%) 2017-12-03T00:04:47.645+0530 [##......................] twitter.sahpur 3133/26000 (12.0%) 2017-12-03T00:04:47.645+0530 2017-12-03T00:04:50.645+0530 [#######.................] twitter.kashmir 69317/210000 (33.0%) 2017-12-03T00:04:50.645+0530 [###########.............] twitter.northkorea 56084/116954 (48.0%) 2017-12-03T00:04:50.645+0530 [################........] viva.external 25361/35922 (70.6%) 2017-12-03T00:04:50.645+0530 [###########.............] twitter.sahpur 12334/26000 (47.4%) 2017-12-03T00:04:50.645+0530 2017-12-03T00:04:52.317+0530 [########################] viva.external 35922/35922 (100.0%) 2017-12-03T00:04:52.317+0530 done dumping viva.external (35922 documents)
Check Dump Location
sachin@sachin-Inspiron-15-3567:~$ ls Desktop Downloads examples.desktop Music Pictures Templates Videos Documents dump mongodb-compass_1.6.0_amd64.deb pgadmin.log Public tweepy VirtualBox VMs sachin@sachin-Inspiron-15-3567:~$ cd dump/ sachin@sachin-Inspiron-15-3567:~/dump$ ls admin twitter viva
All databases dump created with folder name
2. If you want to dump specific database
mongodump --db database_name
3. If you want to dump only one collection in database
mongodump --db database_name --collection cdac
4. If you want to dump all but cdac collection
mongodump --db database_name --excludeCollection=users
5. It is also possible to output the dump to an archive file:
mongodump --archive=test.archive --db database_name
6. Backup database having password
mongodump --username sachin --password xyz@123 --authenticationDatabase admin