> For the complete documentation index, see [llms.txt](https://overleaf-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://overleaf-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 中損壞的 flush，並在 5.0.2 已啟動時略過 flush。

復原所需時間將取決於您執行個體中的專案數量與大小，以及歷史儲存區用於區塊的儲存後端（如在 `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：請手動對文件更新執行 flush，並等待其成功完成。

   如遇錯誤，您可以重複執行該命令。若您在連續執行中看到非零的 `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":"finished flushing all projects","time":"...","v":0}
   所有專案的 flush 已完成
   </code></pre>
6. 如果您從未執行過 5.0.2：請確認所有變更都已從 redis 中 flush 出去。

   如果您從 `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. 嘗試 flush 任何待處理的歷史變更。

   這需要盡力 flush，因為由於不良的資料庫遷移，有些專案的歷史記錄已損壞。任何失敗都會在復原程序結束時透過重新同步歷史記錄來處理。

   <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 %}

#### 追蹤進度

您可以透過 tail 方式查看日誌檔案，以追蹤腳本進度 `/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 %}

#### 等待復原程序完成

透過持續 tail 上述日誌檔案，直到 `完成。` 已列印出一行，或等待 `已完成 doc 版本的復原。` 出現在 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. 選用：執行重新編譯以觸發本機變更的 flush。再次打開「歷史記錄」面板並查看變更。完成後，復原變更。
   {% 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://overleaf-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.
