# Schedules and retention

> Run a plan on a timetable, and decide when Clokeep deletes its old backups from your storage.

A schedule says when a plan runs. Retention says how long, in days or in number of backups, the plan's backups are kept before Clokeep deletes them from your storage.

## Prerequisites

- A Clokeep account with the Admin or Operator role.
- A plan. See [Plans](/docs/backups/plans).

## Pick a schedule

Open the plan. Under **Schedule & retention**, pick a **Schedule** and click **Save changes**. **Manual runs only** means the plan runs only when someone clicks **Run now**.

One schedule can serve many plans. A change to the schedule applies to all of them.

### Create a schedule

<Steps>
<Step title="Open the schedules">
Open **Schedules** and click **New schedule**. Enter a **Name**.
</Step>
<Step title="Enter the timetable">
In **Cron expression**, enter a standard five-part cron expression, such as `0 2 * * *` for 02:00 every day. Shortcuts such as `@daily` and `@hourly` work too. **Schedule preview** spells out what you entered.
</Step>
<Step title="Set the time zone">
**Timezone** is the zone the expression is read in, such as `Europe/Berlin`. It starts as `UTC`. Click **Create**.
</Step>
</Steps>

### When a scheduled time is skipped

Clokeep checks every minute which plans are due. At a due time, it starts no run when:

- **Plan enabled** is off on the plan.
- **Active** is off on the server.
- The plan already has a run that is **Queued** or **Running**. That time is skipped, not made up later.
- The plan cannot run: it has no active storage, nothing to back up, or no agent on its server.

## Retention

Retention has two fields under **Schedule & retention**:

- **Keep backups for**: a number of days.
- **Keep at most**: a number of backups.

Leave both empty to keep backups forever. Each field takes 1 or more.

<Frame caption="Retention on an incremental plan, where both fields apply to chains.">
![The Schedule and retention section with Keep backups for set to 30 days and Keep at most set to 4 backups](/images/docs/schedules-retention-fields.png)
</Frame>

### How the two fields combine

Every hour, Clokeep checks each plan's backups. A backup is deleted as soon as either field says so:

- **Keep at most**: the newest backups, up to the number you set, are kept. Older ones are deleted.
- **Keep backups for**: a backup older than that many days, counted from when it was stored, is deleted.

With both fields set, a backup stays only while it is among the newest and younger than the number of days.

Whatever the fields say, the plan's newest successful backup is never deleted. On an incremental plan, its whole chain stays too. So a plan whose runs keep failing, or whose server is off, keeps its last good backup until a newer one succeeds.

A change to either field applies at the first hourly check after you save: it deletes every backup the new numbers expire. There is no preview and no undo.

A backup here is one run. A run that made several archives, such as one per path or one per hosting account, counts once. Its archives are kept or deleted together, except as described for Plesk server and cPanel server plans below.

Only **Completed** and **Partially completed** runs count. Failed and cancelled runs do not count toward **Keep at most**.

### Archives of failed and stopped runs

A run that fails or is stopped can leave archives on the storage, for example one that finished uploading after you stopped the run. They are not backups: **Browse Backups** does not list them, and they cannot be restored. Clokeep deletes them at an hourly check once a later backup of the plan succeeds, or once they are older than **Keep backups for**. This happens even when both retention fields are empty.

Retention also applies to a plan whose **Plan enabled** is off.

### An example

A Files plan has three backup paths and **Separate archive per path** on, so each run stores three archives. **Keep at most** is 2 and **Keep backups for** is empty. After three completed runs, the next hourly check deletes the three archives of the oldest run. The two newer runs keep all six of theirs.

### Incremental, Plesk and cPanel plans

On an incremental plan, both fields apply to whole chains: a full backup with the incremental backups made after it. **Keep at most** counts chains, and the chain in progress is kept in addition. See [Incremental backups](/docs/backups/incremental).

A Plesk server or cPanel server plan keeps the newest backup of each hosting account, even when it has expired. An account that keeps failing therefore keeps its last good backup.

Keep the **Backup overdue** alert on so you hear when a plan stops producing backups. See [Alerts](/docs/backups/alerts).

### Removed hosting accounts

When an account is removed from Plesk or cPanel, its newest backup is not kept forever. It is kept for 90 days from the sync that first found the account gone. If a plan holding its backups keeps backups for longer, under **Keep backups for**, that longer time applies.

About a week before the end, Clokeep raises a **Removed account backup released soon** alert. It names the account and the day until which its last backup is kept, and says how to keep it. The backup is kept for at least 7 days after that alert, even when the 90 days end sooner.

After that day, the plan's retention applies to the account's backups like to any other, and may delete them. The plan's newest backup is still never deleted.

When every plan holding the account's backups keeps all backups, with **Keep backups for** and **Keep at most** both empty, nothing would be deleted. Clokeep then sends no alert, and the account's row reads "Removed from the server on" a date, then "The plan keeps all backups." If one of those plans gets a retention later, the alert goes out then, and the backup is kept for at least 7 days after it.

- **Keep forever** on the account keeps its last backup for good. See [Plesk servers](/docs/servers/plesk#removed-subscriptions) and [cPanel servers](/docs/servers/cpanel#removed-accounts).
- If the account comes back to the server, the clock stops. Should it be removed again, the 90 days start over.
- Accounts that were already removed before this rule arrived, with Clokeep 4.24.0, count their 90 days from the day of that update.
- The alert follows your alert settings, but the backup is released on time even when nobody receives it.

### What is deleted

For each expired backup, Clokeep deletes the archive and its index from the storage that holds it. Then it removes the backup from the panel. A deleted backup cannot be brought back or restored.

If the storage cannot be reached, the backup is kept. The next hourly check tries again.

Backups that outlived their plan are never deleted by retention.

## Next steps

<CardGroup cols="2">
<Card title="Incremental backups" href="/docs/backups/incremental" icon="layers">
How chains are built, kept and deleted.
</Card>
<Card title="Alerts" href="/docs/backups/alerts" icon="book">
Hear about a plan that stops producing backups.
</Card>
</CardGroup>
