---
type: api
title: Clean up the snapshot repository
description: Trigger the review of the contents of a snapshot repository and delete any stale data not referenced by existing snapshots.
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-snapshot-cleanup-repository
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-snapshot-cleanup-repository
products:
  - Elasticsearch
---

# Clean up the snapshot repository

Availability: Generally available since 7.4

## Paths

- `POST` `/_snapshot/{repository}/_cleanup`

#### Path parameters

- `repository` (string) — required
  The name of the snapshot repository to clean up.

## Description

Trigger the review of the contents of a snapshot repository and delete any stale data not referenced by existing snapshots.

[Read the reference documentation](https://www.elastic.co/guide/en/elasticsearch/reference/8.19/snapshots-register-repository.html#snapshots-repository-cleanup)

## Required authorization

- Cluster privileges: `manage`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/guide/en/elasticsearch/reference/current/token-authentication-services.html)

## Query string parameters

- `master_timeout` (string · default: 30s) — optional
  The period to wait for a connection to the master node.
If the master node is not available before the timeout expires, the request fails and returns an error.
To indicate that the request should never timeout, set it to `-1`
- `timeout` (string · default: 30s) — optional
  The period to wait for a response from all relevant nodes in the cluster after updating the cluster metadata.
If no response is received before the timeout expires, the cluster metadata update still applies but the response will indicate that it was not completely acknowledged.
To indicate that the request should never timeout, set it to `-1`.

## Response

`application/json`

- `results` (object)
  Statistics for cleanup operations.
  - `deleted_blobs` (number)
    The number of binary large objects (blobs) removed from the snapshot repository during cleanup operations.
A non-zero value indicates that unreferenced blobs were found and subsequently cleaned up.
  - `deleted_bytes` (number)
    The number of bytes freed by cleanup operations.
## Code examples

#### Console

```console
POST /_snapshot/my_repository/_cleanup
```

#### JavaScript

```javascript
const response = await client.snapshot.cleanupRepository({
  name: "my_repository",
});
```

#### Python

```python
resp = client.snapshot.cleanup_repository(
    name="my_repository",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_snapshot/my_repository/_cleanup" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.snapshot().cleanupRepository(c -> c
    .name("my_repository")
);
```

#### C#

```c#
var response = await client.Snapshot.CleanupRepositoryAsync(name: "my_repository");
```

#### PHP

```php
$resp = $client->snapshot()->cleanupRepository([
    "repository" => "my_repository",
]);
```

#### Ruby

```ruby
response = client.snapshot.cleanup_repository(
  repository: "my_repository"
)
```

## Response examples

#### Snapshot cleanup repository response example1

A successful response from `POST /_snapshot/my_repository/_cleanup`.

```json
{
  "results": {
    "deleted_bytes": 20,
    "deleted_blobs": 5
  }
}
```

