Reputation: 3415
I have various Mongo databases and when I do ls -l
in my CentOS linux I can see the databaseA.0 and databaseA.ns files for each database and the file size is large enough to tell my data is still there, but when I go to the mongoDB shell by executing the mongo
command and do a show dbs
or show databases
it only shows admin(empty), local 0.078GB, and test(empty).
How do I get my databases back?
Additonal info: When I start the mongo shell I get the following:
MongoDB shell version: 2.6.4
connecting to: test
Server has startup warnings:
2014-08-15T23:23:14.300-0500 [initandlisten]
2014-08-15T23:23:14.300-0500 [initandlisten] ** WARNING: You are running in OpenVZ which can cause issues on versions of RHEL older than RHEL6.
2014-08-15T23:23:14.300-0500 [initandlisten]
2014-08-15T23:23:14.300-0500 [initandlisten] ** WARNING: /proc/sys/vm/zone_reclaim_mode is 1
2014-08-15T23:23:14.300-0500 [initandlisten] ** We suggest setting it to 0
2014-08-15T23:23:14.300-0500 [initandlisten] ** http://www.kernel.org/doc/Documentation/sysctl/vm.txt
2014-08-15T23:23:14.300-0500 [initandlisten]
Upvotes: 5
Views: 27030
Reputation: 65313
dbpath
I would check the dbpath
used by MongoDB is set to what you expect it to be.
In the mongo
shell, run:
db.adminCommand("getCmdLineOpts")
If there is a dbpath
set it will be listed there as parsed.storage.dbPath
(since you are using MongoDB 2.6). If there isn't an explicit setting the dbpath
will default to /data/db
.
If a configuration file was used, you should also see a path to the config listed in parsed.config
.
To fix the dbpath
you need to update the configuration file and restart mongod
.
dbpath
Note that there are two configuration file formats supported by MongoDB 2.6, so you need to match the format of the existing file:
YAML configuration - added in 2.6:
storage:
dbPath: /var/lib/mongo
Legacy INI-style config format - still supported in 2.6, and the likely format if you upgraded from an older version of MongoDB
dbpath = /var/lib/mongo
YAML configurations use semicolons for separators, while the legacy format uses equals signs.
Upvotes: 6
Reputation: 2899
If your mongo client is connected then try db.repairDatabase()
.For more information click here
To repair your data files using the --repairpath
option to preserve the original data files unmodified.
IMPORTANT
: Always Run mongod
as the same user
to avoid changing the permissions of the MongoDB data files.
Start mongod
using --repair
to read the existing data files.
mongod --dbpath /data/db --repair --repairpath /data/db0
When this completes, the new repaired data files will be in the /data/db0
directory.
Start mongod
using the following invocation to point the dbPath
at /data/db0
:
mongod --dbpath /data/db0
Once you confirm that the data files are operational you may delete or archive the old data files in the /data/db
directory. You may also wish to move the repaired files to the old database location or update the dbPath
to indicate the new location.
To repair your data files without preserving the original files, do not use the --repairpath
option, as in the following procedure:
Remove the stale lock file:
rm /data/db/mongod.lock
Replace /data/db
with your dbPath
where your MongoDB instance’s data files reside.
WARNING
: After you remove the mongod.lock
file you must run the --repair
process before using your database.
Start mongod
using --repair
to read the existing data files.
mongod --dbpath /data/db --repair
When this completes, the repaired data files will replace the original data files in the /data/db
directory.
Start mongod
using the following invocation to point the dbPath
at /data/db
:
mongod --dbpath /data/db
source : http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/
Upvotes: 0