> ## 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.

# Get the state of a database snapshot restore

> Follow a database restore with GET /v2/databases/:database_id/snapshots/restore: whether it is queued, running, finished or failed, the step it is on and the error code.

> [!WARNING]
>
> This route has a rate limit of 30 requests every 60 seconds.

**Authorization** `string` *required*

The API key for your account. You can find this in your [account settings](https://squarecloud.app/en/account/security).

Requires an API key with the `snapshots:read` [scope](https://docs.squarecloud.app/en/api-reference/authentication.md#scopes).

Returns the progress and the outcome of the database's last [snapshot restore](https://docs.squarecloud.app/en/api-reference/endpoint/databases/snapshots/restore.md). A database restore loads the whole snapshot into a new database before it replaces the current one, so on a large database it usually outlives the restore route's response and answers `202 SNAPSHOT_RESTORE_PROCESSING`. Poll this route until `state` is `success` or `error`.

The outcome stays available for one hour after the restore ends. After that, or when the database was never restored, `state` is `none`.

## Parameters

**database\_id** `string` *required*

The ID of the database.

## Response

**status** `string`

Indicates whether the call was successful: `success` if it was, `error` if not.

**response** `object`

The contents of the response.

**properties**

**state** `string`

`none` (no recent restore), `queued`, `running`, `success` or `error`.

**step** `string`

The step the restore is on. See [Steps](#steps).

**code** `string`

Why the restore failed. Only when `state` is `error`. See [Failure codes](#failure-codes).

**started\_at** `number`

When the restore started, in Unix milliseconds.

**finished\_at** `number`

When the restore ended, in Unix milliseconds. Only when `state` is `success` or `error`.

```json Running theme={"system"}
{
  "status": "success",
  "response": {
    "state": "running",
    "step": "load",
    "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"
  }
}
```

## Steps

Every restore starts at `queued`, then `inspect`, and ends at `done`. In between, a database goes through these steps, in this order:

| Step | What is happening |
| - | - |
| `download` | The snapshot is being fetched. |
| `preflight`, `verify` | The archive is checked for size and for corruption. Nothing was changed up to here. |
| `pull`, `unzip` | The engine and the snapshot's data are prepared. |
| `stop` | The current database is stopped. It is offline from here until the restore ends. |
| `init`, `load` | A new database is created and the snapshot is loaded into it. This is the longest step. |
| `start` | The new database is started and takes the place of the old one. |
| `cleanup` | What is left of the old database is removed. |

A snapshot of MySQL or MongoDB in the older format adds the step `recovery`. A restore that was cut short ends at the step `interrupted`, with the code `RESTORE_INTERRUPTED`. Treat a step you don't know as "still running": new ones can be added.

## Failure codes

The codes `state: "error"` carries are the same ones the [restore route](https://docs.squarecloud.app/en/api-reference/endpoint/databases/snapshots/restore.md#common-errors) answers with when it fails within its response time:

| Code | Meaning |
| - | - |
| `SNAPSHOT_CORRUPT` | The archive failed its integrity check. The database was not touched. Restore another snapshot. |
| `RESTORE_INTERRUPTED` | The restore was cut short. Run it again. |
| `CONTAINER_NOT_FOUND` | The database was not found on its server. Try again in a moment, and contact support if it persists. |
| `SNAPSHOT_RESTORE_FAILED` | The restore failed for another reason, and the database went back to the data it had. Retry, or restore another snapshot. |

## Polling example

```bash theme={"system"}
DB="https://api.squarecloud.app/v2/databases/$DATABASE_ID/snapshots/restore"

while true; do
  state=$(curl -fsS "$DB" -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
```

## Common errors

| Code | HTTP | Meaning |
| - | - | - |
| `DATABASE_NOT_FOUND` | 404 | The database does not exist or is not owned by the caller. |

## Related

* [Restore Snapshot](https://docs.squarecloud.app/en/api-reference/endpoint/databases/snapshots/restore.md): starts the restore this route follows.
* [List Snapshots](https://docs.squarecloud.app/en/api-reference/endpoint/databases/snapshots/list.md): the snapshots that can be restored.
* [Snapshots and restore](https://docs.squarecloud.app/en/services/databases.md#snapshots-and-restore): what a database snapshot holds and how a restore behaves.


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