If somebody accidentally dropped a MongoDB database but executing db.dropDatabase(), how can he recover the database?
如果有人意外删除了MongoDB数据库但执行了db.dropDatabase(),他怎么能恢复数据库呢?
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?
删除MongoDB中的数据库很简单,命令db.dropDatabase()不会删除它上面的所有数据,而是将其标记为要删除,因此使用drop命令后数据库的大小不会改变,认为应该有一些方法来删除待删除的标记。有人能指出我怎么样?
2 个解决方案
#1
4
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):
我试图重现你做过的事情。在我备份之后,我使用db.dropDatabase()杀死了一个数据库:-) db名称是'gacheater'。在删除mongodb文件夹之前包含3个文件(db非空):
- gacheater.ns
- gacheater.ns
- gacheater.1
- gacheater.1
- gacheater.2
- gacheater.2
after dropping these files disappeared. Therefore I think mongodb really removes your data.
丢弃这些文件后消失了。因此我认为mongodb真的会删除你的数据。
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
#2
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...
AFAIK大多数系统只是通过标志将文件标记为已删除,而不是实际覆盖它。用标准工具恢复文件是可能的......
http://www.cyberciti.biz/tips/linuxunix-recover-deleted-files.html
http://www.cyberciti.biz/tips/linuxunix-recover-deleted-files.html
These might be easier to work with
这些可能更容易使用
http://extundelete.sourceforge.net/
http://extundelete.sourceforge.net/
As pointed out no substitute for backups.
正如所指出的那样,无法替代备份。
#1
4
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):
我试图重现你做过的事情。在我备份之后,我使用db.dropDatabase()杀死了一个数据库:-) db名称是'gacheater'。在删除mongodb文件夹之前包含3个文件(db非空):
- gacheater.ns
- gacheater.ns
- gacheater.1
- gacheater.1
- gacheater.2
- gacheater.2
after dropping these files disappeared. Therefore I think mongodb really removes your data.
丢弃这些文件后消失了。因此我认为mongodb真的会删除你的数据。
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
#2
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...
AFAIK大多数系统只是通过标志将文件标记为已删除,而不是实际覆盖它。用标准工具恢复文件是可能的......
http://www.cyberciti.biz/tips/linuxunix-recover-deleted-files.html
http://www.cyberciti.biz/tips/linuxunix-recover-deleted-files.html
These might be easier to work with
这些可能更容易使用
http://extundelete.sourceforge.net/
http://extundelete.sourceforge.net/
As pointed out no substitute for backups.
正如所指出的那样,无法替代备份。