- Administration >
- MongoDB Backup Methods >
- Recover a Standalone after an Unexpected Shutdown
Recover a Standalone after an Unexpected Shutdown¶
Warning
The following procedure applies to standalone mongod
instance version 4.4. For other MongoDB versions, refer to
the corresponding version of the manual.
Do not use this tutorial to recover a member of a replica set. Instead, you should either restore from a backup or resync from another member of the set, as described in Resync a Member of a Replica Set.
Tip
If you are running with journaling enabled, there is almost never any need to run repair since the server can use the journal files to restore the data files to a clean state automatically. However, you may need to run repair in cases where you need to recover from a disk-level data corruption.
Disk-level data corruption or missing data files can prevent
mongod
instance from starting, and journal files may be
insufficient to recover automatically:
In such cases, your dbPath
contains a non-empty
mongod.lock
file.
The following procedure uses mongod --repair
to recover from
these cases:
Warning
Only use mongod --repair
if you have no other options.
The operation removes and does not save any corrupt data during the
repair process.
Starting in MongoDB 4.4, for the WiredTiger storage engine,
mongod --repair
:
- Rebuilds all indexes for collections with one or more inconsistent indexes.
- Discards corrupt data.
- Creates empty/stub files for missing data/metadata files.
Procedure¶
Important
Run the repair operation as the same user that normally runs the
mongod
process to avoid changing the permissions of the
MongoDB data files.
Note
If the repair fails to complete for any reason, you
must restart the instance with the --repair
option to complete the repair.
[1] | (1, 2) Generally, you should not manually remove the mongod.lock file.
Instead, use the above procedure to recover the database. In dire
situations, you can remove the file, start the database using the
possibly corrupt files, and attempt to recover data from the
database. However, it is impossible to predict the state of the
database in these situations. |