Recover a Standalone after an Unexpected Shutdown意外关闭后恢复单机
The following procedure applies to standalone 以下过程适用于7.0版的独立mongod
instance version 7.0. For other MongoDB versions, refer to the corresponding version of the manual.mongod
实例。对于MongoDB的其他版本,请参阅相应版本的手册。
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.请勿使用本教程恢复复制副本集的成员。相反,您应该从备份中恢复,或者从该集的另一个成员中重新同步,如resync a member of a Replica set中所述。
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:mongod
实例启动,并且日志文件可能不足以自动恢复:
2018-10-24T18:05:18.248-04:00 W STORAGE [initandlisten] Detected unclean shutdown - mongod.lock is not empty.
...
2018-10-24T17:24:53.122-04:00 E STORAGE [initandlisten] Failed to get the cursor for uri: table:collection-2-6854866147293273505
2018-10-24T17:24:53.122-04:00 E STORAGE [initandlisten] This may be due to missing data files. ...
...
***aborting after fassert() failure
In such cases, your 在这种情况下,dbPath
contains a non-empty mongod.lock
file.dbPath
包含一个非空的mongod.lock
文件。
The following procedure uses 以下过程使用mongod --repair
to recover from these cases:mongod --repair
从这些情况中恢复:
Only use 只有在没有其他选择的情况下才使用mongod --repair
if you have no other options. The operation removes and does not save any corrupt data during the repair process.mongod --repair
。在修复过程中,该操作将删除并且不保存任何损坏的数据。
Starting in MongoDB 4.4, for the WiredTiger storage engine, 从MongoDB 4.4开始,对于WiredTiger存储引擎,mongod --repair
: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过程
Run the repair operation as the same user that normally runs the 以正常运行mongod
process to avoid changing the permissions of the MongoDB data files.mongod
进程的同一用户身份运行修复操作,以避免更改MongoDB数据文件的权限。
Start mongod
with --repair
.用--repair
启动mongod
。
mongod
with --repair
.To repair the data files, start the 要修复数据文件,请使用mongod
instance with the --repair
option.--repair
选项启动mongod
实例。
Issue a command similar to the following for your standalone:为您的单机版发出类似于以下内容的命令:
mongod --dbpath /data/db --repair
Upon completion, the 完成后,dbpath
should contain the repaired data files and an empty mongod.lock
file. dbpath
应该包含修复的数据文件和一个空的mongod.lock
文件。[1]
[1] | mongod.lock file. Instead, use the above procedure to recover the database. mongod.lock 文件。相反,请使用上面的过程来恢复数据库。 |