---
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/4371/api/doc/elasticsearch/v8/operation/operation-snapshot-cleanup-repository
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/operation/operation-snapshot-cleanup-repository
products:
  - Elasticsearch
---

# Clean up the snapshot repository

Availability: 7.4+

## Paths

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

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#basicauth)
- [Bearer auth](/elastic/docs-builder/docs/4371/api/doc/elasticsearch/v8/authentication#bearerauth)

#### Path Parameters

- `repository` (string Name)
  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.

## Required authorization

* Cluster privileges: `manage`

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

## Query String Parameters

- `master_timeout` (string Duration · default: 30s)
  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 Duration · default: 30s)
  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` ({} CleanupRepositoryResults)
  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
  }
}
```

