Question

Next question in reference with previous one Where does mongodb store databse in ubuntu?

$ cd /var/lib/mongodb/
$ ls
ihtx.0  ihtx.1  ihtx.ns  journal  local.0  local.ns  mongod.lock

Here, I can see ihtx.0 ihtx.1 ihtx.ns three files with the same name. Here which one is mydatabase which I usually see in mongo shell? which one should I dump ?

Tried each, getting following error :

$ mongodump --dbpath /var/lib/mongodb/ihtx.XX --out /home/user/Desktop/

If you are running a mongod on the same path you should connect to that instead of direct data file access

Thu Mar 13 11:17:21.123 dbexit: 
Thu Mar 13 11:17:21.123 [tools] shutdown: going to close listening sockets...
Thu Mar 13 11:17:21.123 [tools] shutdown: going to flush diaglog...
Thu Mar 13 11:17:21.123 [tools] shutdown: going to close sockets...
Thu Mar 13 11:17:21.123 [tools] shutdown: waiting for fs preallocator...
Thu Mar 13 11:17:21.123 [tools] shutdown: closing all files...
Thu Mar 13 11:17:21.123 [tools] closeAllFiles() finished
Thu Mar 13 11:17:21.123 [tools] shutdown: removing fs lock...
Thu Mar 13 11:17:21.123 [tools] couldn't remove fs lock errno:9 Bad file descriptor
Thu Mar 13 11:17:21.123 dbexit: really exiting now
Was it helpful?

Solution

This command will work for you If your dbpath is set or you mongoDB service is Running here ihtx denotes your dbname

$ mongodump -d ihtx --out /home/user/Desktop/intxDB

OTHER TIPS

ihtx.0,ihtx.1,ihtx,ns represent the database ihtx.

The .0 .1 etc. files are the data files themselves. MongoDB names the first data file .0, the next .1, etc. The first file mongod allocates is 64 megabytes, the next 128 megabytes, and so on, up to 2 gigabytes, at which point all subsequent files are 2 gigabytes.

The ".ns" files are namespace files. Each collection and index would count as a namespace. Each namespace is 628 bytes, the .ns file is 16MB by default.

Now in your question, mongod instance is not able to remove fs lock(as you can see in the error).

Thu Mar 13 11:17:21.123 [tools] closeAllFiles() finished
Thu Mar 13 11:17:21.123 [tools] shutdown: removing fs lock...
Thu Mar 13 11:17:21.123 [tools] couldn't remove fs lock errno:9 Bad file descriptor
Thu Mar 13 11:17:21.123 dbexit: really exiting now 

As in your code, dbpath is /var/lib/mongodb, so When you are starting mongo instance, use --dbpath parameter as given :

mongod --dbpath=/var/lib/mongodb

So first run following command:

mongod --dbpath=/var/lib/mongodb --repair

After that run following :

mongodump --dbpath /var/lib/mongodb -d ihtx --out /home/user/Desktop/intxDB

For your first question 'Which is my database file?', please refer the link http://docs.mongodb.org/manual/faq/storage/

It clearly mentions that, "MongoDB preallocates data files to a particular size, in part to prevent file system fragmentation. MongoDB names the first data file .0, the next .1, etc."

And for the error which you are getting while taking dump, Remove the --dbpath option and then try.

You either export from a running server, or from the files (if the server isn't running, or locked), not both.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top