> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cortex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Deleting archived entities automatically

> Set how long Cortex keeps archived entities before permanently deleting them

Archived entities stay in Cortex until someone deletes them. If you ingest short-lived resources, such as cloud instances that are created and torn down often, archived entities can pile up quickly. An auto-deletion policy tells Cortex how long to keep an archived entity before permanently deleting it.

You can set a default policy for new entity types and set a different policy for any individual entity type. By default, Cortex never deletes archived entities. Nothing is deleted until you choose a policy.

> [!WARNING]
>
> Auto-deletion is permanent. Deleted entities, and their history and data, can't be restored. Before you apply a policy, check which archived entities it will delete.

## How auto-deletion works

* Each night, Cortex finds archived entities that have been archived longer than their type's auto-deletion policy and permanently deletes them.
* The policy counts from the date the entity was archived. For example, with a 30-day policy, an entity archived on March 1 is deleted in the first nightly run on or after March 31.
* If an entity is unarchived before its policy runs out, it isn't deleted.
* If you shorten a policy, Cortex starts deleting any archived entities already past the new window in the next nightly run.
* Each nightly run that deletes entities adds one summary entry to your [audit log](https://docs.cortex.io/configure/settings/notifications/logs.md). The entry shows the run under the **System** actor.

Available policies are **After 30 days**, **After 60 days**, **After 90 days**, **After 180 days**, **After 365 days**, and **No auto-delete**.

## Setting an auto-deletion policy

Users with the `Edit Settings` permission can set auto-deletion policies.

1. From the main sidebar, click your avatar in the bottom-left corner.
2. Select **Settings**.
3. From the **Settings** menu, locate the **Workspace** section, then expand **Entities**.
4. Select the **General** tab.
5. Scroll to the **Archive and deletion policies** section.
6. Under **Defaults for new entity types**, select a policy from the auto-deletion dropdown next to **All new entity types**. This policy applies to any entity type you add later. To change existing entity types, use the **Settings by entity type** table.

### Setting a policy for an entity type

The **Settings by entity type** table lists every entity type with its number of entities, number of archived entities, and the date of its next auto-deletion.

* To change one type, select a policy in its **Auto-deletion policy** column.
* To change several types at once, select the checkbox next to each type, then select a policy from the **Auto-deletion policy** drop-down in the bulk changes bar at the bottom of the table.

To narrow the table, click **Filter** and filter by **Cloud providers**, **Auto-archiving source**, or **Auto-deletion policy**.

To set one policy for every entity type from a cloud provider, filter by that provider, select every matching type, then select a policy in the bulk changes bar. When every type from the provider is selected, the bulk changes bar notes that new types from that provider are included, and the policy also applies to that provider's entity types you add later.

A policy set on an entity type overrides the default.

### Reviewing archived entities before they're deleted

In the **Settings by entity type** table, the **Next auto-deletion** column shows when Cortex will next delete archived entities of that type. To see which entities are archived, click the arrow in the **View archived** column. A side panel lists the archived entities for that type.

When an archived entity is scheduled for deletion, a banner on its details page shows the date it will be deleted and how many days are left.

To keep an entity, [unarchive it](https://docs.cortex.io/ingesting-data-into-cortex/entities-overview/entities/archiving-entities/archiving-entities-manually.md#unarchiving-an-entity-via-the-cortex-ui) before its policy runs out, or set its type's policy to **No auto-delete**.

## Setting auto-deletion policies via the Cortex API

You can read and update auto-deletion policies with the API endpoints to [get the entity archival configuration](https://docs.cortex.io/api/rest/entity-archival/get-entity-archival-configuration.md) and [update the entity archival configuration](https://docs.cortex.io/api/rest/entity-archival/update-entity-archival-configuration.md). Set `retentionDays` per entity type under `entityTypes`, or for new types under `defaultForNewEntityTypes`. Allowed values are `0` (never), `30`, `60`, `90`, `180`, and `365`.

To set one policy for every entity type from a cloud provider, use `providerRetentionDays`, keyed by `AWS`, `GCP`, or `AZURE`. A policy set on an individual type overrides the provider policy.


## Related topics

- [Archiving entities automatically](https://docs.cortex.io/ingesting-data-into-cortex/entities-overview/entities/archiving-entities/auto-archive.md)
- [Entity settings](https://docs.cortex.io/configure/settings/entity-settings.md)
- [Archiving entities](https://docs.cortex.io/ingesting-data-into-cortex/entities-overview/entities/archiving-entities.md)
