> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# 获取应用 snapshot 恢复的状态

> 通过 GET /v2/apps/:app_id/snapshots/restore 跟踪 snapshot 恢复：它是在排队、运行中、已完成还是已失败，当前所处的步骤以及错误代码。

> [!WARNING]
>
> 此路由的速率限制为每 60 秒 30 次请求。

**Authorization** `string` *required*

你账户的 API 密钥。你可以在[账户设置](https://squarecloud.app/zh/account/security)中找到它。

需要具有 `snapshots:read` [权限范围](https://docs.squarecloud.app/zh/api-reference/authentication.md#权限范围)的 API 密钥。

返回应用最近一次 [snapshot 恢复](https://docs.squarecloud.app/zh/api-reference/endpoint/apps/snapshots/restore.md)的进度和结果。当恢复返回 `202 SNAPSHOT_RESTORE_PROCESSING` 时使用它，这表示恢复仍在后台运行：轮询此路由，直到 `state` 为 `success` 或 `error`。

恢复结束后，结果会保留一小时。超过这个时间，或者应用从未被恢复过时，`state` 为 `none`。在工作区共享的应用上，调用者需要具备 `admin` [角色](https://docs.squarecloud.app/zh/api-reference/endpoint/workspace/members/invite.md#角色)。

## 参数

**app\_id** `string` *required*

应用的 ID。你可以在应用控制面板的 URL 中找到它。

## 响应

**status** `string`

指示调用是否成功。成功时为 `success`，否则为 `error`。

**response** `object`

响应的内容。

**属性**

**state** `string`

`none`（近期没有恢复）、`queued`、`running`、`success` 或 `error`。

**step** `string`

恢复当前所处的步骤。参见[步骤](#步骤)。

**code** `string`

恢复失败的原因。仅当 `state` 为 `error` 时出现。参见[失败代码](#失败代码)。

**started\_at** `number`

恢复开始的时间，以 Unix 毫秒表示。

**finished\_at** `number`

恢复结束的时间，以 Unix 毫秒表示。仅当 `state` 为 `success` 或 `error` 时出现。

```json Running theme={"system"}
{
  "status": "success",
  "response": {
    "state": "running",
    "step": "unzip",
    "started_at": 1760900000000
  }
}
```

```json Failed theme={"system"}
{
  "status": "success",
  "response": {
    "state": "error",
    "step": "done",
    "code": "SNAPSHOT_CORRUPT",
    "started_at": 1760900000000,
    "finished_at": 1760900042000
  }
}
```

```json No recent restore theme={"system"}
{
  "status": "success",
  "response": {
    "state": "none"
  }
}
```

## 步骤

每次恢复都从 `queued` 开始，然后是 `inspect`，最后以 `done` 结束。在这之间，应用会按以下顺序经过这些步骤：

| 步骤 | 正在发生什么 |
| - | - |
| `download` | 正在获取 snapshot。 |
| `preflight` | 对照应用的存储空间检查它的大小和文件数量。 |
| `verify` | 读取整个归档文件并检查是否损坏。到这一步为止，没有任何内容被更改。 |
| `lock`、`stop` | 应用被停止。 |
| `wipe`、`unzip` | 当前文件被 snapshot 中的文件替换。 |
| `start` | 应用被重新启动。 |

被中断的恢复会以步骤 `interrupted` 结束，代码为 `RESTORE_INTERRUPTED`。请把你不认识的步骤视为“仍在运行”：今后可能会增加新的步骤。

## 失败代码

`state: "error"` 携带的代码，与[恢复路由](https://docs.squarecloud.app/zh/api-reference/endpoint/apps/snapshots/restore.md#常见错误)在其响应时间内失败时返回的代码相同：

| 代码 | 说明 |
| - | - |
| `SNAPSHOT_CORRUPT` | 归档文件未通过完整性检查。应用的文件没有被改动。请恢复另一个 snapshot。 |
| `RESTORE_INTERRUPTED` | 恢复被中断。请重新运行。 |
| `CONTAINER_NOT_FOUND` | 在应用所在的服务器上找不到它。请稍后重试，如果问题持续，请联系支持团队。 |
| `SNAPSHOT_RESTORE_FAILED` | 恢复因其他原因失败。请重试，或恢复另一个 snapshot。 |

## 轮询示例

```bash theme={"system"}
APP="https://api.squarecloud.app/v2/apps/$APP_ID/snapshots/restore"

while true; do
  state=$(curl -fsS "$APP" -H "Authorization: $SQUARECLOUD_API_KEY" | jq -r .response.state)
  case "$state" in
    success) echo "Restored."; break ;;
    error|none) echo "Restore ended as: $state"; exit 1 ;;
  esac
  sleep 5
done
```

## 常见错误

| 代码 | HTTP | 说明 |
| - | - | - |
| `APP_NOT_FOUND` | 404 | 应用不存在，或调用者无法访问它。 |

## 相关内容

* [恢复 snapshot](https://docs.squarecloud.app/zh/api-reference/endpoint/apps/snapshots/restore.md)：启动此路由所跟踪的恢复。
* [列出 snapshot](https://docs.squarecloud.app/zh/api-reference/endpoint/apps/snapshots/list.md)：可以恢复的 snapshot。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.