# Take and roll back instance snapshots

> Save an instance's disk, and optionally its memory, as a snapshot you can roll back to on the same instance.

Source: https://docs.coritan.com/cloud-compute/snapshots/

In the dashboard:

- /dashboard/compute/…/snapshots: https://www.coritan.com/dashboard/compute

A *snapshot* saves the state of an instance's disk at one moment, so you can return the disk to that state later. Take one before a risky change, such as an upgrade, and roll back if the change goes wrong. An instance can hold 8 snapshots at a time.

A snapshot lives on the same storage as the instance's disk. It is quick to take and to roll back to, but it goes with the disk. A [rebuild](/cloud-compute/rebuild/) or a cancellation deletes it, and restoring a backup leaves it unusable. For a copy that survives a rebuild, [create a backup](/cloud-compute/backups/).

## Before you begin

- The instance is not suspended.
- To include the memory, the instance is running.

## Take a snapshot

1. In the [dashboard](https://www.coritan.com/dashboard/compute), go to **Cloud Compute**, open the instance and select the **Snapshots** tab.
2. Select **Take snapshot…**.
3. Under **Name**, type a name such as `before-upgrade`. Start with a letter, and use letters, digits, hyphens and underscores. Keep it to 37 characters or fewer: the form accepts 40, but a longer name fails when we take the snapshot.
4. Optionally, add a **Description** of up to 255 characters.
5. To save the memory as well, tick **Include memory (RAM state)**. Rolling back to the snapshot then resumes the instance exactly where it was. The snapshot is larger, and the instance pauses while we save its memory.
6. Select **Take snapshot**.

The snapshot appears in the table with its **Contents**, `Disk` or `Disk and memory`, and when it was **Taken**.

## Roll back to a snapshot

Rolling back returns the disk to the snapshot and loses everything written to it since.

1. On the **Snapshots** tab, open the menu at the end of the snapshot's row and select **Roll back…**.
2. Type the snapshot's name to confirm, then select **Roll back**.

We shut the instance down, roll the disk back and start it again. A snapshot with memory resumes from its saved state. The snapshot stays, so you can roll back to it again later.

> [!TIP]
> Take a fresh snapshot before you roll back if you might need the current state.

## Delete a snapshot

1. On the **Snapshots** tab, open the menu at the end of the snapshot's row and select **Delete snapshot…**.
2. Type the snapshot's name to confirm, then select **Delete snapshot**.

Deleting a snapshot frees its space on the storage. The instance itself does not change.

## Result

The table lists each snapshot with its status, and the card above it counts how many of the 8 you use. A snapshot that failed does not count.

## Troubleshooting

`Snapshot limit reached`
: The instance holds 8 snapshots. Delete one before you take another.

`Snapshot name must be alphanumeric (start with a letter), max 40 chars`
: The name has a character a snapshot name cannot hold, or does not start with a letter. Use letters, digits, hyphens and underscores only.

`Snapshot failed`
: The host could not take the snapshot. A name longer than 37 characters is one cause. Choose a shorter name and try again.

`Rollback failed` after you rolled back a snapshot with memory
: The instance may have rolled back anyway. Open the **Console** tab and check its state before you try again.

`Rollback failed` or `Delete snapshot failed` after a rebuild or a restore
: The rebuild or the [backup restore](/cloud-compute/backups/#restore-a-backup) replaced the disk the snapshot belonged to, and the snapshot can no longer be used. If a rollback stopped the instance, start it again from the header.

## Related

- [Back up and restore an instance](/cloud-compute/backups/) for copies kept on separate storage.
- [Rebuild an instance](/cloud-compute/rebuild/) explains what a rebuild erases.
- [Cloud Compute limits](/cloud-compute/limits/) lists the snapshot limit with the others.

## With the API

`GET /api/v1/client/vps/{uuid}/snapshots` lists the instance's snapshots, newest first. Each has an `id`, `name`, `description`, `vmstate` (`1` when it holds memory), `status` and `created_at`. `status` is `creating`, `ready`, `rolling_back`, `deleting` or `failed`.

`POST /api/v1/client/vps/{uuid}/snapshots` takes a snapshot. Send `name`; `description` and `vmstate` are optional, and `vmstate` is `false` when left out. The request returns when the snapshot is ready.

```bash
curl -X POST https://api.coritan.com/api/v1/client/vps/$INSTANCE_UUID/snapshots \
  -H "Authorization: Bearer $CORITAN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "before-upgrade", "description": "Before the kernel upgrade", "vmstate": false}'
```

```json
{"id": 3, "name": "before-upgrade", "proxmox_snapname": "cc-before-upgrade", "status": "ready"}
```

A ninth snapshot answers `409` with `Snapshot limit of 8 reached`. A name the rules refuse answers `400`, and so does a snapshot the host could not take, with a message that starts `Snapshot failed`.

`POST /api/v1/client/vps/{uuid}/snapshots/{snapshot_id}/rollback` rolls back to a snapshot whose `status` is `ready`, and answers `{"status": "rolled_back", "id": 3}` once the instance runs again. Any other snapshot answers `404` with `Snapshot not found or not ready`.

`DELETE /api/v1/client/vps/{uuid}/snapshots/{snapshot_id}` deletes a snapshot and answers `{"status": "deleted", "id": 3}`. You can delete snapshots while the instance is suspended.

Taking a snapshot and rolling back answer `403` with `Instance is suspended` on a suspended instance. While we move the instance to another host, taking, rolling back and deleting answer `409` with `Instance is migrating`.

## API

- `GET /api/v1/client/vps/{uuid}/snapshots`: List snapshots (https://docs.coritan.com/api/reference/client/cloud-compute/#op-get-api-v1-client-vps-uuid-snapshots)
- `POST /api/v1/client/vps/{uuid}/snapshots`: Create snapshot (https://docs.coritan.com/api/reference/client/cloud-compute/#op-post-api-v1-client-vps-uuid-snapshots)
- `DELETE /api/v1/client/vps/{uuid}/snapshots/{snapshot_id}`: Delete snapshot (https://docs.coritan.com/api/reference/client/cloud-compute/#op-delete-api-v1-client-vps-uuid-snapshots-snapshot-id)
- `POST /api/v1/client/vps/{uuid}/snapshots/{snapshot_id}/rollback`: Rollback snapshot (https://docs.coritan.com/api/reference/client/cloud-compute/#op-post-api-v1-client-vps-uuid-snapshots-snapshot-id-rollback)
