13
Backup and Restore Database in MongoDB By: Prem Regmi

Backup, restore and repair database in mongo db linux file

Embed Size (px)

Citation preview

Page 1: Backup, restore and repair database in mongo db linux file

Backup and Restore Database in MongoDB

By: Prem Regmi

Page 2: Backup, restore and repair database in mongo db linux file

RESTORING THEM

What’s the most important thing about making backups?

Page 3: Backup, restore and repair database in mongo db linux file

Backup Options

• Mongodump• Copy files• Snapshot disk

Page 4: Backup, restore and repair database in mongo db linux file

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

mongodump

Page 6: Backup, restore and repair database in mongo db linux file

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

mongodump

Page 8: Backup, restore and repair database in mongo db linux file

mongorestore

• mongorestore• Restore all database inside dump

Page 9: Backup, restore and repair database in mongo db linux file

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

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

Solution

• Remove the mongod.lock file• Run the --repair process

Page 12: Backup, restore and repair database in mongo db linux file
Page 13: Backup, restore and repair database in mongo db linux file