# Restore a cluster from a snapshot

Return every Kubernetes object of a cluster to one of its verified etcd snapshots.

Replace _my-cluster_ with your cluster's name, and _etcds-0123456789ab_ with the snapshot's id.

**Warning:**
Every object created after the snapshot is gone, and the Kubernetes API is down until the first new
control-plane machine has restored etcd (about 5 to 10 minutes).

## Prerequisites

- Permission for `eks:RestoreCluster` on the cluster.
- In the console, also `eks:DescribeCluster` to open the cluster and `eks:ListClusterSnapshots` to
  see the snapshots.
- The cluster is `active` (one restore at a time, none during an upgrade or a deletion), and the
  snapshot is verified.

## Restore

**Console**
1. Open **Kubernetes**, open the cluster, then choose **Backups**.
2. Under **Snapshots**, open the snapshot's menu and choose **Restore…**. Only verified snapshots
   have it.
3. In the dialog, enter the cluster name, and choose **Restore**.

**CLI**
```sh
dcloud eks snapshots list my-cluster
dcloud eks clusters restore my-cluster --snapshot-id etcds-0123456789ab --confirm my-cluster
```

**API**
```http
POST /eks/api/clusters/my-cluster/restore
{ "snapshotId": "etcds-0123456789ab", "confirm": "my-cluster" }
```

## Result

The answer is `202` with the cluster in status `restoring`. Then:

1. On a control plane built with backups, a `pre-restore` snapshot of the current state is taken
   first, so the restore can be undone. The restore waits for it at most 15 minutes; if it fails
   or does not arrive, the restore goes on without it, and **Activity** says so.
2. Every control-plane machine is replaced. One new machine restores etcd from the snapshot and
   starts the control plane with the same CA, endpoint and keys, so kubeconfigs keep working.
3. On `standard`, the other two machines are added.

Worker nodes keep running their pods and reconnect when the API is back. **Activity** records each
step and who asked. A restore you start is excluded from the SLA for its first 30 minutes. When
the control plane is complete again, the cluster is `active`.

If the first new machine fails, or is not up within 30 minutes, the restore fails: the cluster is
`failed`, its error starts "Restore failed:", and Deutsche Cloud's operators are told.

## Refusals

- `400` "Confirm with the cluster’s name (_my-cluster_)".
- `404` "Snapshot not found" for a snapshot not of this cluster.
- `409` "Only a verified snapshot can be restored".
- `409` "The cluster is _updating_; a restore starts only from an active cluster (one at a time,
  not during an upgrade or a deletion)".

## Related

- [Back up a cluster](back-up-a-cluster.md)
- [Restore a deleted cluster](restore-a-deleted-cluster.md)
- `eks.clusters.restore` · `dcloud eks clusters restore`
