# Restore an expired image

Bring back an image a lifecycle rule deleted, with the tags nothing has taken since, before it is purged.

An image a lifecycle rule deleted stays restorable until its purge time. Replace
repository-id with the repository's id and the digest with the image's.

## Prerequisites

- Permission for `ecr:RestoreExpiredItem` on the repository.
- To list expired images: `ecr:GetLifecyclePolicy` on the repository. Without it the console's
  **Lifecycle policy** tab says so.
- In the console, also `ecr:DescribeRepositories` on the repository; without it its page answers 404.

## Restore it

**Console**
1. Open **Image repositories**, open the repository, then the **Lifecycle policy** tab.
2. Under **Recently deleted by a rule**, find the image by **Tags it had** and **Digest**.
   **Why** says which rule deleted it, **Purged** when it goes for good, and **Pulled since**
   whether something tried to pull it since.
3. Choose **Restore**.

A signature or SBOM row has no **Restore**: it comes back with its image.

**CLI**
```sh
dcloud ecr expired-images list repository-id
dcloud ecr expired-images restore repository-id \
  --digest sha256:0f3e5c1b2a4d6e8f0a1b3c5d7e9f1a2b4c6d8e0f2a4b6c8d0e2f4a6b8c0d2e4f
```

**API**
```http
POST /ecr/api/repositories/repository-id/expired-images/restore
{ "digest": "sha256:0f3e5c1b2a4d6e8f0a1b3c5d7e9f1a2b4c6d8e0f2a4b6c8d0e2f4a6b8c0d2e4f" }
```

## Result

`200` with `restoredTags`, the tags given back, and `takenTags`, those another image holds by now,
which stay where they are. A multi-platform image comes back with its platform images, and every
image with its signatures. The restore is recorded on the repository.

If the rule still selects the image, the next hourly run deletes it again; give the repository a
policy that keeps it first (see [Set a lifecycle policy](set-a-lifecycle-policy.md)).

## If it is refused

- `404` `No restorable expired image with that digest` when it was never expired or is purged.
- `409` with code `QuotaExceeded` while the organization's or the repository's storage quota is
  already full.

## Related

- [Lifecycle policies](lifecycle-policies.md)
- `ecr.expired-images.restore` · `dcloud ecr expired-images restore`
