开发者

How to recover a dropped MongoDB database?

开发者 https://www.devze.com 2023-03-17 23:24 出处:网络
If somebody accidentally dropped a MongoDB database but executing db.dropDatabase(), how开发者_JS百科 can he recover the database?

If somebody accidentally dropped a MongoDB database but executing db.dropDatabase(), how开发者_JS百科 can he recover the database?

Dropping a database in MongoDB is simple, and the command db.dropDatabase() won't erase all the data on it but marks it as to be deleted, so the size of the database would not change after using the drop command, which I think there should be some way to remove the to-be-deleted marker. Can some one point me how?


I tried to reproduce what you had done. I killed a database using db.dropDatabase() after I had backed it up :-) The db name was 'gacheater'. Before dropping mongodb folder contained 3 files (the db is non-empty):

  • gacheater.ns
  • gacheater.1
  • gacheater.2

after dropping these files disappeared. Therefore I think mongodb really removes your data.

So the only choice you have is to try to restore files from the filesystem

PS: MacOS 10.5, MongoDB 1.8.2


AFAIK most systems just mark the file as deleted, via a flag rather than actually overwriting it. It's possible to recover files with standard tools...

http://www.cyberciti.biz/tips/linuxunix-recover-deleted-files.html

These might be easier to work with

http://extundelete.sourceforge.net/

As pointed out no substitute for backups.

0

精彩评论

暂无评论...
验证码 换一张
取 消