# MongoServerError: OplogTruncationFailed: 恢复期间命名空间 local.oplog.rs 的 oplog 条目被截断

- **ID:** `mongodb/oplog-truncation-after-point-in-time-recovery`
- **领域:** mongodb
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 70%

## 根因

从备份进行时间点恢复期间，由于恢复时间戳超出 oplog 窗口或 oplog 损坏，oplog 被截断。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |
| MongoDB 8.0 | active | — | — |

## 解决方案

1. ```
   Perform a full resync of the affected secondary from a healthy primary using rs.reconfig() or initial sync.
   ```
2. ```
   Use mongodump/mongorestore with --oplogReplay to restore from a backup that includes a consistent oplog window.
   ```
3. ```
   If the primary is affected, promote a secondary with a valid oplog using rs.stepDown() and rs.reconfig().
   ```

## 无效尝试

- **** — Oplog size change affects future operations, not past truncation. (90% 失败率)
- **** — Incompatible backup may have different oplog range, causing further errors. (70% 失败率)
- **** — Direct modification can corrupt the replica set and cause data loss. (100% 失败率)
