![Page 1: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/1.jpg)
Backup and Restore Database in MongoDB
By: Prem Regmi
![Page 2: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/2.jpg)
RESTORING THEM
What’s the most important thing about making backups?
![Page 3: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/3.jpg)
Backup Options
• Mongodump• Copy files• Snapshot disk
![Page 4: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/4.jpg)
mongodump
• Dumps collections to *.bson files• Mirrors your structure• Can be run in live or offline mode-
![Page 5: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/5.jpg)
mongodump
![Page 6: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/6.jpg)
mongodump
• Type mongodump in your terminal• mongodump --db hero(hero is the database
name)• Database save inside dump folder
![Page 7: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/7.jpg)
mongodump
![Page 8: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/8.jpg)
mongorestore
• mongorestore• Restore all database inside dump
![Page 9: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/9.jpg)
Repair• Repair all databases on the server:
• $ mongod –repair
• Repair Database command to repair a single
• database:
> use project_development
> db.runCommand({repairDatabase: 1})
• which operate on a single collection :
rebuild indexes>use tuotorial_development> db.employee_qualifications.reIndex()
compact the collection
> db.runCommand({ compact: "employee_qualifications" }
![Page 10: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/10.jpg)
Recover MongoDB
• Unexpected Shutdown• Error: couldn't connect to server 127.0.0.1
shell/mongo.js:84
![Page 11: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/11.jpg)
Solution
• Remove the mongod.lock file• Run the --repair process
![Page 12: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/12.jpg)
![Page 13: Backup, restore and repair database in mongo db linux file](https://reader036.vdocuments.site/reader036/viewer/2022062406/558bc2fad8b42adf4b8b45ef/html5/thumbnails/13.jpg)