1

I am in the process of moving my mongo data to a different drive. All of the data I want to move is stored in /data/db and I am moving it to a NAS (Network attached storage).

First step:

mongodump -d mydb -c mycollection -o nas/mongo-temp

This created a file tree in mongo-temp/ like so:

dump
`-- mydb
    `-- mycollection.bson

1 directory, 1 file

I then stopped the mongod service and created a new /data/db directory:

/etc/init.d/mongod stop
mkdir mongo-temp/data/db

...and changed the dbpath line in /etc/mongodb.conf

dbpath=.../mongo-temp/data/db

I successfully restarted the mongo server using /etc/init.d/mongod start.

When I try to connect:

mongo
MongoDB shell version: 1.6.4
Thu May  3 09:53:23 *** warning: spider monkey build without utf8 support.  consider rebuilding with utf8 support
connecting to: test
Thu May  3 09:53:24 Error: couldn't connect to server 127.0.0.1 (anon):1154
exception: connect failed

I've tried to start mongod with the command mongod --dbpath .../mongo-temp/data/db but I get an error that says:

Thu May  3 09:57:26 exception in initAndListen std::exception: Unable to acquire lock for lockfilepath: /home/dlpstats/nas-mnt/mongo-temp/data/db/mongod.lock

Removing the lockfile doesn't help. If I run the mongod command without --dbpath, the server starts fine and I am able to make queries on my old database.

3 Answers 3

2

First, you mentioned that you used mongodump to populate the new drive - was this just a method of backing things up or did you intend that to be the new database files? That is not how it works - mongodump output is not the same as a database file - it needs to be re-imported with mongoresore in fact. If you do a straight data file copy then the transfer will be seamless.

Then, as well as the permissions suggested by Wes in his answer, a few more things to check:

  1. That you have shut down the old server successfully and completely - it's possible it's mis-reported error and you are getting it because it is trying to grab a port that is already open
  2. You are using version 1.6.4 according to the mongo shell output, my guess is that you installed from the Ubuntu repo for 11.04 or similar, that is not a good option - 1.6 is very old at this point. Use the 10gen repos (http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages) or download the binaries and get a more recent version

Last but not least, when you start the mongod manually, make sure all the arguments are the same, like the port. When you connect via the mongo shell, specify the port you started the mongod on - don't rely on defaults when running into issues like this, be explicit.

7
  • dump is just a backup method. I'm aware of restore and intend to use it once I get the server working. I will check on 1 and 2. Thanks
    – SemperFly
    May 3, 2012 at 20:01
  • I'm on CentOS. I followed the steps at mongodb.org/display/DOCS/CentOS+and+Fedora+Packages to install mongo. Is there a newer repository source for centos?
    – SemperFly
    May 3, 2012 at 20:04
  • No, that is the correct source, but you seem to be running a very old version - perhaps you installed mongodb (which would hit your default repo) and not mongo-10gen etc. which will get you 2.0.4 at present, not 1.6.4 May 3, 2012 at 20:23
  • I've been tinkering since updating and still nothing. I believe the NAS may have something to do with it. I'm able to create a local directory as a database source for MongoDB just fine. But when I mount the nas, and use that directory, the unable to acquire lockfile error comes up.
    – SemperFly
    May 3, 2012 at 21:59
  • what filesystem is the NAS using? If it is Windows/MAC formatted I wonder if that could be the cause of your issues.... May 4, 2012 at 8:03
1

I faced this problem and issuing following command solved my problem:

rm /var/lib/mongodb/mongod.lock 

And then restart the mongod.

But I'm not sure is it a good solution or not.

0

Check the permissions for the directory and parent directories of mongo-temp. Presumably it's running as the mongodb user?

You need execute permissions on the directory (and parent directories) in order to create files there. Execute permissions on a directory allow you to list the files there, which is needed to be able to open the file for writing.

6
  • I've tried various permissions including what you have above. Same result.
    – SemperFly
    May 3, 2012 at 17:36
  • 1
    Set a shell in the mongodb user in /etc/passwd, and then switch to that user and try going to that folder and creating a file. If you can create a file, then it's not a permissions issue. I have a strong feeling it is, though. May 3, 2012 at 17:37
  • Still no dice. It's able to create the lockfile but can't "acquire a lock".
    – SemperFly
    May 3, 2012 at 18:22
  • Can you open the file, put something in it, and save it? (as mongodb user) May 3, 2012 at 18:30
  • 1
    And mongodb owns the lock file? If so, I guess I'm out of suggestions as far as permissions go. May 3, 2012 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.