> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/on-premises/zh-cn/zhi-chi/support-guides/doc-version-recovery.md).

# （v5.0.1 迁移）文档版本恢复

{% hint style="info" %}
如果你从未运行过 Server Pro 5.0.1 版或 Community Edition 5.0.1 版，或者你是使用 5.0.1 启动了一个全新的实例，则无需运行此恢复流程。
{% endhint %}

**本页更新：**

* （2024-04-22 13:40 BST）：新增步骤“阻止新的更新进入系统，并将所有更改刷新到 MongoDB”。
* （2024-04-23 11:45 BST）：考虑 5.0.1 中失效的刷新，并在启动 5.0.2 后跳过刷新。

恢复所需时间取决于实例中的项目数量和大小，以及用于块历史存储的存储后端（如在 `OVERLEAF_HISTORY_CHUNKS_BUCKET`).

恢复流程会延迟 Server Pro 容器内应用的启动。在此期间，网站将显示为离线。我们仅支持从一个 Server Pro 容器实例中运行恢复，所有其他水平扩展工作进程都需要离线。

如有需要，你可以停止并继续恢复流程。

根据我们的性能测试，在现代硬件（3GHz CPU 时钟速度和本地 NVMe 存储）上，恢复流程大约每分钟可处理 1 万个小项目。举例来说，对于一个有 10 万个项目的实例，请安排一个至少允许 10+2 分钟停机时间的维护窗口。使用以下查询来估算你实例中的项目数量：

{% code overflow="wrap" %}

```bash
$ docker exec mongo mongosh sharelatex --quiet --eval 'db.projects.estimatedDocumentCount() + db.deletedProjects.estimatedDocumentCount()'
```

{% endcode %}

在开始之前，请完整阅读以下恢复步骤。Server Pro 客户欢迎随时联系 <support@overleaf.com> 咨询任何问题。

### 恢复流程

{% stepper %}
{% step %}

#### 拉取发布镜像

拉取 `5.0.3` 发布镜像。
{% endstep %}

{% step %}

#### 找出几个项目

通过 ID 找出几个缺少历史记录的项目；理想情况下，你有权限对其中一个进行更改。
{% endstep %}

{% step %}

#### 安排维护

为停机安排一个维护窗口。
{% endstep %}

{% step %}

#### 停止除一个工作进程外的所有进程

在使用水平扩展架构时，停止除一个工作进程外的所有进程。
{% endstep %}

{% step %}

#### 停止新的更新并将所有更改刷新到 MongoDB

阻止新的更新进入系统，并将所有更改刷新到 MongoDB：

1. 通过以下地址的管理面板手动关闭编辑器并断开所有用户连接 `https://my-server-pro.example.com/admin#open-close-editor` ，在“打开/关闭编辑器”选项卡中。
2. 停止 Websocket/实时服务。

   ```bash
   $ docker exec sharelatex sv stop real-time-overleaf
   ```
3. 等待实时服务退出，标志如下 `down:`.

   ```bash
   $ docker exec sharelatex sv status real-time-overleaf
   run: real-time-sharelatex: (pid 394) 50s, want down, got TERM
   # 再等一会儿...

   $ docker exec sharelatex sv status real-time-overleaf
   down: real-time-sharelatex: 7s, normally up
   ```
4. 如果启用了 git-bridge 容器，请停止它。

   ```bash
   $ docker stop git-bridge
   ```
5. 如果你从未运行过 5.0.2：手动刷新文档更新，并等待其成功完成。

   如果出现错误，你可以重复该命令。若你看到一个非零的 `failureCount` 在连续运行中，请停止迁移（通过以下方式恢复服务： `docker restart git-bridge sharelatex`）并联系支持团队。

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">$ docker exec sharelatex bash -c 'source /etc/container_environment.sh &#x26;&#x26; source /etc/overleaf/env.sh &#x26;&#x26; cd services/document-updater &#x26;&#x26; LOG_LEVEL=info node scripts/flush_all.js'
   ...
   {"name":"default","hostname":"...","pid":324,"level":30,"successCount":...,"failureCount":0,"msg":"已完成所有项目的刷新","time":"...","v":0}
   所有项目刷新完成
   </code></pre>
6. 如果你从未运行过 5.0.2：确保所有更改都已从 redis 中刷新出去。

   如果你从以下命令得到任何输出 `redis-cli`，请停止迁移（通过以下方式恢复服务： `docker restart git-bridge sharelatex`）并联系支持团队。

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">$ docker exec redis redis-cli --scan --pattern 'DocVersion:*'
   # redis-cli 没有输出表示成功，接下来检查 redis-cli 的退出码，它应该为零
   $ echo $?
   0
   </code></pre>
7. 尝试刷新任何待处理的历史更改。

   由于错误的数据库迁移，一些项目的历史记录已损坏，因此这将需要尽最大努力进行刷新。任何失败都将在恢复流程结束时通过重新同步历史来处理。

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">$ docker exec sharelatex bash -c 'source /etc/container_environment.sh &#x26;&#x26; source /
   </code></pre>

{% endstep %}

{% step %}

#### 备份

考虑进行一次 [一致性备份](https://docs.overleaf.com/on-premises/maintenance/data-and-backups#performing-a-consistent-backup) 实例备份。
{% endstep %}

{% step %}

#### 升级

升级到版本 `5.0.3`.
{% endstep %}

{% step %}

#### 自动恢复

恢复流程会在容器启动时自动运行。
{% endstep %}

{% step %}

#### 跟踪进度

你可以通过持续查看日志文件来跟踪脚本进度 `/var/lib/overleaf/data/history/doc-version-recovery.log`。它会在开始时打印项目总数，并在每处理 1000 个项目后打印一份摘要。

{% code overflow="wrap" %}

```bash
$ docker exec sharelatex tail --retry --follow /var/lib/overleaf/data/history/doc-vers
```

{% endcode %}
{% endstep %}

{% step %}

#### 等待恢复流程完成

你可以通过持续查看上面的日志文件直到出现一条 `完成。` 行，或者等待 `已完成文档版本恢复。` 出现在 Server Pro 容器的标准输出中。
{% endstep %}

{% step %}

#### 验证恢复流程

通过打开之前缺少历史记录的几个项目的历史面板来验证恢复流程。

1. 加快待测试项目的重新同步（它们最终会被处理，但我们不想等到轮到它们。）

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">$ docker exec sharelatex curl -X POST --silent "http://127.0.0.1:3054/project/000000000000000000000000/resync?force=true"
   </code></pre>

   （对每个要测试的项目 ID 重复此操作，将 `000000000000000000000000` 替换为每次一个项目 ID。）
2. 打开这些项目的项目编辑器 `https://my-server-pro.example.com/project/000000000000000000000000`
3. 打开项目的“历史记录”面板并查看最新内容。
4. 可选：再次关闭“历史记录”面板。进行一次代码更改，例如在开头添加注释。
5. 可选：重新编译以触发本地更改的刷新。再次打开“历史记录”面板并查看更改。完成后，撤销该更改。
   {% endstep %}

{% step %}

#### 对于水平扩展……

再次启动其他工作进程。
{% endstep %}

{% step %}

#### 保持实例运行

请保持执行恢复流程的实例继续运行。它将在后台以并发数 1 重新同步所有项目的历史记录。这会导致基础负载略有升高。（你可以重启实例，但它需要重新开始重新同步。）
{% endstep %}

{% step %}

#### 完成后请告知我们

Server Pro 客户：在完成恢复流程后，请通知支持团队。
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/on-premises/zh-cn/zhi-chi/support-guides/doc-version-recovery.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
