last day (15 days later) » 

2:54 PM
0
Q: mongodump references wrong db directory

Brian FlanaganI had an install of MongoDB that was using on OSX that was using ~/data/db. I had a crash and re-installed MongoDB using Homebrew and it set up the new db path at ~/usr/local/var/mongodb. All of my apps are working (default port 27017), but when I try to run mongodump it backs up the db in ~/...

 
What version of mongodump are you using and how exactly are you calling it? By simply executing mongodump in the terminal?
 
The version is 3.6.5. And yep, calling it from terminal. (I'm also using it in a bash script but it performs the same way for both.)
 
Since version 3.2 (IIRC) mongodump does not accept --dbpath argument. It now requires a live server. So chances are good that either a) you're mistaken about which data dir your server uses or b) there are two servers on the machine and mongodump is talking to a wrong one.
 
I'm confident about the correct data dir. Timestamps show which one is getting updated. Not sure about two servers running though... how could I check that?
 
Try something like ps aux | grep mongod. Followup question: How do you know that mongodump dumps the wrong data dir?
 
2:54 PM
Looks like there might be two running: 367 0.0 0.2 5226396 27108 ?? S 14Feb19 6:03.43 /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf 72163 0.0 0.0 4277252 824 s010 S+ 9:48AM 0:00.00 grep mongod
 
Nah, the last line is your grep
Try this: ps aux | grep mongod | grep -v grep
 
I killed the older process but the dump still seems to be grabbing the wrong db...
Yeah, this is really weird... I've added a new database since this all stopped working correctly. It's not showing up in the mongodump. I also did a restore and the data was a few weeks old.
I renamed /data/db to /data/db_old... but mongodump is still backing up the old data. No idea how that's happening.
ps aux | grep mongod | grep -v grep returned nothing...
And now my db looks to be offline.
 
Yes, if you killed that mongod, you have no live server now. So your apps should stop working, but so should mongodump!
Does it keep working?
 
Yep.
Even better... I restarted mongo and it's pulling the old dbs.
 
Look at your config file, /usr/local/etc/mongod.conf. What db path does it specify?
 
3:02 PM
/usr/local/var/mongodb
 
And mongod runs as /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf?
 
no idea... :)
 
Do the ps aux thingie :)
 
72532 0.0 0.2 5124944 41028 s010 S+ 10:03AM 0:01.19 mongod
 
Ah, yes, back to default settings.
Weird how did this happen?
 
3:04 PM
That's what I wanna know. hehe
 
How did you kill and restart it?
 
kill {number}
mongod
 
Ah, that's why
brew services start mongodb
or mongod, or whatever brew calls it
But stop this one first
 
interesting... said it was already started. I did a restart...
Bam... Got database back.
lemme check mongodump
Shoot... mongodump is still using the old db...
 
no way, that's impossible
 
3:08 PM
I believe you...
 
You said you renamed the folder, how can it still be dumping it?
It must be dumping the live database.
 
Sorry... I brought it back after the db was dead. Lemme rename again and retry
renamed... mongodump still not showing the new stuff. This is really weird.
I'm using robo 3t to access the db. It's showing the latest db.
My app is dead though.
 
Try restarting the app.
 
That did it.
Ok, so I still can't get mongodump to work...
 
I think I'll need to see your screen to help you any further. Feel free to hit me up on codementor :)
 
3:13 PM
Ok.
And now it's working...
I was running mongodump with sudo and specifying an --out directory. Tried just running it without parameters and it worked. Then added the out directory back and it worked again.
Could it have been cached?
Maybe because I was using sudo?
 
Cache? No. But sudo could have been the reason. Another user, another environment, another $PATH. Can lead to another mongodump binary.
 
Makes sense (I guess). hehe.
Thanks for the help!
 
you're welcome :)
 

last day (15 days later) »