{"id":13473,"date":"2019-12-29T07:39:14","date_gmt":"2019-12-29T07:39:14","guid":{"rendered":"https:\/\/ittutorial.org\/?p=13473"},"modified":"2019-12-29T07:39:14","modified_gmt":"2019-12-29T07:39:14","slug":"mongodb-backup-and-restore-using-mongodump","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/mongodb-backup-and-restore-using-mongodump\/","title":{"rendered":"MongoDB Backup and Restore Using MongoDump"},"content":{"rendered":"<p>In case if you feel that you want to take a backup of your files and folders in MongoDB then follow me through this article.<\/p>\n<p>we will be using mongodumo and mongorestore for our backup and restore methodology. mongodump\u00a0reads data from a MongoDB database and creates high fidelity BSON files which the\u00a0mongorestore\u00a0tool can use to populate a MongoDB database.\u00a0mongodump\u00a0and\u00a0mongorestore\u00a0are simple and efficient tools for backing up and restoring small MongoDB deployments, but are not ideal for capturing backups of larger systems. <a href=\"https:\/\/docs.mongodb.com\/manual\/core\/backups\/#back-up-with-mongodump\">read more<\/a><\/p>\n<h6>Taking backup using mongodump:<\/h6>\n<pre>[root@srv1 mongo]# mongodump --out=\/home\/mongoBackup --db=mughees\r\n2019-10-21T13:32:48.421+0300 writing mughees.myNewCollection1 to \r\n2019-10-21T13:32:48.422+0300 writing mughees.myNewCollection2 to \r\n2019-10-21T13:32:48.425+0300 done dumping mughees.myNewCollection1 (3 documents)\r\n2019-10-21T13:32:48.427+0300 writing mughees.myNewCollection3 to \r\n2019-10-21T13:32:48.429+0300 done dumping mughees.myNewCollection3 (0 documents)\r\n2019-10-21T13:32:48.431+0300 done dumping mughees.myNewCollection2 (1 document)<\/pre>\n<p>&#8211;out ==&gt; to provide the path where it will take backup output to.<\/p>\n<p>&#8211;db ==&gt; name of the database of which you wot take backup.<\/p>\n<h6>DROP mughees DB:<\/h6>\n<pre>&gt;show databases\r\nadmin 0.000GB\r\nconfig 0.000GB\r\nlocal 0.000GB\r\nmughees 0.000GB\r\n\r\ndb.dropDatabase()\r\n\r\ndb.dropDatabase()\r\n{ \"dropped\" : \"mughees\", \"ok\" : 1 }\r\n&gt; \r\n\r\nNow we will create a mughees DB again and check if there is any collection available\r\n&gt; use mughees \r\nuse mughees\r\nswitched to db mughees \r\n&gt; show collectionsshow collections #no collection will be shown \r\n&gt;<\/pre>\n<p>No collections have been shown as the database has been dropped<\/p>\n<pre>&gt; show databases;\r\nshow databases;\r\nadmin 0.000GB\r\nconfig 0.000GB\r\nlocal 0.000GB<\/pre>\n<p>We do have created mughees DB but DB is not created until and unless you create any collection inside the DB.<\/p>\n<h6>Now restore Mughees DB:<\/h6>\n<p>Now lets resotre the our backup of mughees db make sure you have created the database with same.<\/p>\n<pre>[root@srv1 mongo]# mongorestore --db=mughees \/home\/mongoBackup\/mughees\r\n\r\n2019-10-21T13:41:34.773+0300 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead\r\n2019-10-21T13:41:34.774+0300 building a list of collections to restore from \/home\/mongoBackup\/mughees dir\r\n2019-10-21T13:41:34.776+0300 reading metadata for mughees.myNewCollection1 from \/home\/mongoBackup\/mughees\/myNewCollection1.metadata.json\r\n2019-10-21T13:41:34.783+0300 reading metadata for mughees.myNewCollection2 from \/home\/mongoBackup\/mughees\/myNewCollection2.metadata.json\r\n2019-10-21T13:41:34.784+0300 reading metadata for mughees.myNewCollection3 from \/home\/mongoBackup\/mughees\/myNewCollection3.metadata.json\r\n2019-10-21T13:41:34.828+0300 restoring mughees.myNewCollection1 from \/home\/mongoBackup\/mughees\/myNewCollection1.bson\r\n2019-10-21T13:41:34.832+0300 no indexes to restore\r\n2019-10-21T13:41:34.832+0300 finished restoring mughees.myNewCollection1 (3 documents, 0 failures)\r\n2019-10-21T13:41:34.866+0300 restoring mughees.myNewCollection2 from \/home\/mongoBackup\/mughees\/myNewCollection2.bson\r\n2019-10-21T13:41:34.869+0300 no indexes to restore\r\n2019-10-21T13:41:34.871+0300 finished restoring mughees.myNewCollection2 (1 document, 0 failures)\r\n2019-10-21T13:41:34.881+0300 restoring mughees.myNewCollection3 from \/home\/mongoBackup\/mughees\/myNewCollection3.bson\r\n2019-10-21T13:41:34.895+0300 restoring indexes for collection mughees.myNewCollection3 from metadata\r\n2019-10-21T13:41:34.921+0300 finished restoring mughees.myNewCollection3 (0 documents, 0 failures)\r\n2019-10-21T13:41:34.921+0300 4 document(s) restored successfully. 0 document(s) failed to restore.\r\n[root@srv1 mongo]#<\/pre>\n<h6>Check the restore database:<\/h6>\n<p>Now let&#8217;s check it the db and the collections inside are available or not :<\/p>\n<pre>&gt;show databases;\r\nadmin 0.000GB\r\nconfig 0.000GB\r\nlocal 0.000GB\r\nmughees 0.000GB\r\n&gt; &gt; use mugheesuse mughees\r\nswitched to db mughees\r\n&gt; show collectionsshow collections\r\nmyNewCollection1\r\nmyNewCollection2\r\nmyNewCollection3<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In case if you feel that you want to take a backup of your files and folders in MongoDB then follow me through this article. we will be using mongodumo and mongorestore for our backup and restore methodology. mongodump\u00a0reads data from a MongoDB database and creates high fidelity BSON files which the\u00a0mongorestore\u00a0tool can use to &hellip;<\/p>\n","protected":false},"author":10455,"featured_media":13475,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6797,6798],"tags":[204,6800,7200,7201,6931,6427],"class_list":["post-13473","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-mongodb","category-nosql","tag-backup","tag-mongodb","tag-mongodump","tag-mongorestore","tag-nosql","tag-restore"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/12\/mongodb-restore.jpg","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/users\/10455"}],"replies":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/comments?post=13473"}],"version-history":[{"count":2,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13473\/revisions"}],"predecessor-version":[{"id":13476,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13473\/revisions\/13476"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media\/13475"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=13473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=13473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=13473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}