> 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-tw/zhi-yuan/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. 等待即時服務結束，如 `下：`.

   ```bash
   $ docker exec sharelatex sv status real-time-overleaf
   run: real-time-sharelatex: (pid 394) 50s, 想要 down，但收到 TERM
   # 再等一下...

   $ docker exec sharelatex sv status real-time-overleaf
   down: real-time-sharelatex: 7s，正常應為 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>

   （針對每個要測試的 project-id 重複執行，將 `000000000000000000000000` 一次替換為一個 project-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-tw/zhi-yuan/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.
