# 還原已刪除的資料庫

> 在刪除後的五天內還原資料庫與群組。
> Canonical HTML: https://tursodb.cn/zh-tw/docs/features/recover-deleted-databases/
> Upstream Source (MIT): https://docs.turso.tech/features/recover-deleted-databases
> Language: zh-TW

---
Turso Cloud 會將已刪除的資料庫與群組保留最多 **五天**，讓你能夠還原。還原會將資料庫精確地回復到刪除當下的狀態——相同名稱、相同資料。無論刪除是來自隊友、指令碼，還是過於熱心的 AI 代理，這都能保護你免於意外。

所有付費方案皆可免費使用還原功能，不額外收費。

<div class="doc-callout doc-callout-info"><div class="doc-callout-title">注意</div><div class="doc-callout-body">

這與[時間點還原](/zh-tw/docs/features/point-in-time-recovery/)
（PITR）不同。PITR 會將**現有**資料庫還原到較早的時間點，但無法找回已刪除的資料庫。還原功能則是將**已刪除**的資料庫回復到刪除當下的狀態。

</div></div>


## 需求

* **付費方案**。在組織處於付費方案期間刪除的資料庫才能還原。
* 對組織具有**管理員或擁有者**權限。
* 組織已啟用還原功能（**允許還原** 開關——請參閱
  [下方](#disabling-recovery)）。

## 從儀表板還原

1. 在 [Turso 儀表板](https://app.turso.tech) 開啟 **還原** 頁面。
2. 在 **最近刪除** 下找到該資料庫——你可以依名稱、ID、
   主機名稱或群組搜尋。
3. 點擊 **還原**。

已刪除的群組會顯示在同一頁面的獨立區塊中。還原群組時，也會嘗試還原隨該群組一併刪除的資料庫。

## 使用 Platform API 還原

列出過去五天內刪除的資料庫，然後依資料庫的 UUID 進行還原：

```bash List deleted databases
curl -L 'https://api.turso.tech/v3/organizations/{organizationId}/databases?deleted=true' \
  -H 'Authorization: Bearer TOKEN'
```

```bash Restore a database
curl -L -X POST 'https://api.turso.tech/v3/organizations/{organizationId}/databases/{databaseId}/restore' \
  -H 'Authorization: Bearer TOKEN'
```

```bash List deleted groups
curl -L 'https://api.turso.tech/v3/organizations/{organizationId}/deleted-groups' \
  -H 'Authorization: Bearer TOKEN'
```

```bash Restore a group
curl -L -X POST 'https://api.turso.tech/v3/organizations/{organizationId}/groups/{groupId}/restore' \
  -H 'Authorization: Bearer TOKEN'
```

這些端點一律以 **UUID** 而非名稱來識別物件：
`{organizationId}` 是
[取得組織](/zh-tw/docs/api-reference/organizations/retrieve/) 回應中的 `id` 欄位，而
資料庫與群組的 UUID 則來自已刪除項目的列表。若要以不同名稱還原（例如舊名稱已被
新資料庫使用時），請傳入 JSON 主體：`{ "name": "my-restored-database" }`。

所有參數與回應欄位請參閱 API 參考文件：

<div class="doc-cards">
<a class="doc-card" href="/zh-tw/docs/api-reference/databases/list-deleted/"><div class="doc-card-title"><span>列出已刪除的資料庫</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
<a class="doc-card" href="/zh-tw/docs/api-reference/databases/restore/"><div class="doc-card-title"><span>還原資料庫</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
<a class="doc-card" href="/zh-tw/docs/api-reference/groups/list-deleted/"><div class="doc-card-title"><span>列出已刪除的群組</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
<a class="doc-card" href="/zh-tw/docs/api-reference/groups/restore/"><div class="doc-card-title"><span>還原群組</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
</div>


## 使用 AI 代理還原

[Turso MCP 伺服器](/zh-tw/docs/integrations/mcp/) 將還原功能開放給 AI 代理使用，因此
誤刪資料庫的代理可以在同一個工作階段中將其復原：

| 工具 | 說明 |
| - | - |
| `list_deleted_databases` | 列出過去五天內刪除的資料庫。回傳還原所需的 UUID。 |
| `restore_database` | 依 UUID 還原已刪除的資料庫，可選擇使用新名稱。 |
| `list_deleted_groups` | 列出過去五天內刪除的群組，包括空群組。 |
| `restore_group` | 還原已刪除的群組，以及隨其一併刪除的資料庫。 |

## 還原群組

銷毀群組會刪除其所有資料庫。還原群組時，會將群組復原，並嘗試還原這些資料庫。
若部分資料庫還原失敗，群組仍會恢復為啟用狀態——你可以使用 `restore_database`
個別重試失敗的資料庫。

## 停用還原功能

有些組織需要讓「已刪除」就是真正刪除。管理員與擁有者可以透過儀表板還原頁面上的
**允許還原** 開關、API 或 MCP 伺服器
（`set_organization_restore_enabled`），為整個組織關閉還原功能：

```bash
curl -L -X PATCH 'https://api.turso.tech/v1/organizations/{organizationSlug}' \
  -H 'Authorization: Bearer TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{ "restore_enabled": false }'
```

目前狀態會由
[取得組織](/zh-tw/docs/api-reference/organizations/retrieve/) 以 `restore_enabled`
回傳。

在還原功能停用期間，已刪除的資料庫與群組仍會出現在已刪除列表中，但還原嘗試會
失敗，直到管理員或擁有者重新啟用還原功能為止。

## 須知事項

* 還原期限為刪除後 **五天**。超過之後，資料庫將永久消失。
* 還原是以資料庫的 **UUID** 而非名稱來識別——名稱可以重複使用。若已有新資料庫
  使用舊名稱，請以新名稱還原已刪除的資料庫。
* 還原後的資料庫包含截至刪除當下已提交的所有內容。若要回溯更早的時間點，請接著
  使用[時間點還原](/zh-tw/docs/features/point-in-time-recovery/)。
* 還原需要區域支援：出現在已刪除列表中，並不保證該資料庫一定能還原。
* 若要從根本避免刪除，請在
  [資料庫](/zh-tw/docs/api-reference/databases/update-configuration/) 或
  [群組](/zh-tw/docs/api-reference/groups/update-configuration/) 上啟用 **刪除保護**
  ——受保護的資料庫在關閉保護之前無法被刪除。

<div class="doc-cards">
<a class="doc-card" href="/zh-tw/docs/features/point-in-time-recovery/"><div class="doc-card-title"><span>時間點還原</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
<a class="doc-card" href="/zh-tw/docs/integrations/mcp/"><div class="doc-card-title"><span>MCP（AI 代理）</span><span class="doc-card-arrow" aria-hidden="true">→</span></div></a>
</div>
