Is it possible to recover MongoDB databases from .ns and .0, .1, . ... files?
The .ns .0 .1
etc. files are the data files themselves. If you started a mongod
instance with a --dbpath
argument pointing at that folder, or if you moved the contents somewhere else and used the option to point there, mongod will attempt to read them as normal.
Since your issues suggest corruption and/or some other issue starting mongod
(you should really post the startup messages log files, perhaps in a separate question to address that issue), then there are alternatives. For reference, the most common problems are permissions related, especially when people try to start mongod manually (as themselves) or with sudo (as root) and create problematic permissions in the various directories.
You are correct that mongorestore
cannot use these data files directly, but mongodump
can read them and dump data from them into the BSON files that mongorestore
expects.
The option you want here is dbpath. You mention your path is /var/lib/mongo
, so you can run something like this:
mongodump --dbpath /var/lib/mongo -d <database name> -o /path/to/put/files
Optionally you can use --repair
here too to fix corruption along with the query options in extreme circumstances to get around corrupted sections (rarely, if ever, needed). The various options are described on the mongodump
page:
http://docs.mongodb.org/manual/reference/mongodump/
Once you dump the files out, you can use mongorestore
to reimport them into another mongod
instance.