如何恢复已删除的MongoDB数据库? [英] How to recover a dropped MongoDB database?

查看:641
本文介绍了如何恢复已删除的MongoDB数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人不小心删除了MongoDB数据库但执行了db.dropDatabase(),他如何恢复数据库?

If somebody accidentally dropped a MongoDB database but executing db.dropDatabase(), how can he recover the database?

在MongoDB中删除数据库很简单,并且命令db.dropDatabase()不会删除其上的所有数据,但会将其标记为已删除,因此在使用drop命令后,数据库的大小不会改变,我认为应该有一些方法可以删除待删除的标记.有人可以指点我吗?

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?

推荐答案

我试图重现您所做的事情.在备份数据库后,我使用db.dropDatabase()杀死了一个数据库:-)数据库名称为'gacheater'.在删除mongodb文件夹之前,该文件夹包含3个文件(数据库为非空):

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

消失了.因此,我认为 mongodb确实删除了您的数据.

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

PS: MacOS 10.5, MongoDB 1.8.2

这篇关于如何恢复已删除的MongoDB数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆