How to recover from losing all your /data/db

707 views Asked by At

We are using mongodb 3.0.2 and our system is managed via MMS We discover the one of our new DEV environment lost all the content for the /data/db including the journals, logs and config file.

One thing is the the instance is still up and running in memory.

Does anyone has a solution on how to recover from this situation?

I tried a db.fsyncLock() that is supposed to flush to data into disk but no luck.

1

There are 1 answers

2
Sylvain Leroux On

AFAICT, as the files are already opened/memmapped by MongoDB, removing their entry from the filesystem will not prevent MongoDB to still use them (on Unix-like systems, at least). As long as they are not closed and that MongoDB do not need to open other files, things should still be usable. Enough to start doing some dumps.

As an experiment, I populated a newly installed MongoDB 3.0.2 instance with 2M documents. Stopping it, restarting it, and removing the data folder -- before having even accessed the collection. Finally I was able to mongodump that collection without any issue:

> for (i = 0; i < 2000000; ++i) { db.test.insert({x:i}) }
# Stop MongoDB
# Start MongoDB again

rm -rf data

mongodump -d test -c test 
# success !

# Stop MongoDB

mkdir -p data/db

# Start MongoDB again

mongorestore -d test -c test dump/test/test.bson 
> db.test.count()
2000000