---
title: "Lifecycle"
sidebarTitle: "Lifecycle"
description: "Use lifecycle rules to delete files automatically after a while, clean up noncurrent versions, and abort multipart uploads that never finish."
layout: overview
tags: Preview
tags-style: border
---

Lifecycle rules clean up content a bucket no longer needs:

- Delete files some days after they were last modified, or after a given date.
- In buckets with [versioning](/bitiful-s4/handbook/versioning), permanently delete noncurrent versions after some days, and clean up files that have only a delete marker left.
- Abort multipart uploads that started long ago and never finished, and free the uploaded parts.

<Note>
  Lifecycle is in preview. It is live on the storage side, and the console entry is rolling out account by account: accounts that don't have it yet won't see the **Lifecycle** tab on the bucket page. To use it early, please [contact support](/contact).
</Note>

<Warning>
  Deletions made by rules **can't be undone**. Without rules, the system never deletes anything in a bucket automatically, and there are no default rules.
</Warning>

## When rules run

Rules run once a day at **03:00 (Beijing time)**, and each run applies only rules saved before 03:00. There's no extra waiting period after you save:

| Saved at | First run |
| --- | --- |
| Before 03:00 (for example, 02:50) | 03:00 the same day |
| After 03:00 (for example, 03:10 or 14:00) | 03:00 the next day |

- If the rules change while a run is in progress, that day's run for the bucket stops, and the new rules apply from 03:00 the next day.
- There can be up to about a day between a file expiring and it actually being deleted, and it's billed as usual in the meantime.

## Create a rule

Go to **Object storage › [Buckets](https://console.bitiful.com/buckets)** › click the bucket name › **Lifecycle**.

<Frame>
  ![The Lifecycle page: the rule list, run status with estimated impact, and recent activity](/assets/console/bucket-lifecycle-en.webp)
</Frame>

<Steps>
  <Step title="Create a rule">
    Click **Create rule** and enter a **Rule name**. Recent activity uses it to show which rule deleted what.
  </Step>
  <Step title="Choose the scope">
    Choose **Entire bucket** or **Prefix**, and optionally filter further by tags and file size. See [Scope](#scope).
  </Step>
  <Step title="Choose actions">
    Choose at least one action. See [Actions](#actions). The bottom of the dialog sums up what the rule will do in one sentence.
  </Step>
  <Step title="Save the rules">
    You can add several rules, then click **Save rules** when you're done. The confirmation lists the actions that can't be undone and when the next run is.
  </Step>
</Steps>

### Scope

| Condition | Description |
| --- | --- |
| Prefix | Files whose object key starts with it. `logs/` means every file in the `logs` folder; a prefix without a trailing `/` matches names that start with it. Up to 1024 bytes |
| Tags | Only files that have all of these tags. Tag keys are 1 to 128 characters, and values up to 256 characters |
| Files larger than, Files smaller than | Filters by file size; the lower bound must be smaller than the upper bound |

### Actions

| Action | Description |
| --- | --- |
| Expire current versions | Expires files **some days after they were last modified**, or **from a given date** |
| Expire noncurrent versions | Permanently deletes noncurrent versions **some days after they became noncurrent**, optionally **always keeping the newest few** (1 to 100). Runs only in buckets with versioning enabled |
| Remove delete markers | When all versions of a file have been cleaned up and only a delete marker is left, removes that marker too. Runs only in buckets with versioning enabled |
| Abort multipart upload | Aborts multipart uploads that are still unfinished some days after they started, and removes the uploaded parts |

What "Expire current versions" does depends on the versioning state:

| Versioning state | Effect of expiration |
| --- | --- |
| Not enabled | Permanently deletes the file; it can't be recovered |
| Enabled | Adds a delete marker so the file disappears from the list. The data becomes a noncurrent version and is still kept and billed. To actually free the space, also set up "Expire noncurrent versions" |
| Suspended | Removes the copy written while suspended and leaves a delete marker |

Rule limits:

- Up to 1000 rules per bucket. Rule names are up to 255 characters and must be unique.
- Dates are midnight UTC, which is 08:00 Beijing time. If the date has passed, the next run after you save immediately processes every file in scope, and files written later are processed too.
- "Remove delete markers" can't be combined with tag filters.
- "Abort multipart upload" can't be combined with tag or file size filters, and uploads still receiving parts recently aren't aborted.
- Expiring noncurrent versions deletes them permanently. Versions protected by [Object Lock](/bitiful-s4/handbook/object-lock) are skipped.

## Estimated impact and activity

A few minutes after you save, the page shows the **Estimated impact** of this version of the rules: based on the current data, how many items the rules will process and how much space that is. It's only a dry run and deletes nothing, and the rules don't wait for it. For rules saved shortly before 03:00, it may appear only after the run. The actual numbers depend on the data at run time.

**Run status** shows whether today's run has finished and how many items were deleted, skipped, or failed. **Recent activity** lists what the rules actually deleted, covering only the latest 50 entries from the last 30 days. Each entry's result is one of:

| Result | Meaning |
| --- | --- |
| Deleted | Deleted |
| Skipped: protected by Object Lock | The version is within its retention period or under legal hold. It wasn't deleted this time and will be checked again in the next run |
| Failed | This item wasn't processed and will be retried in the next run |

## Recommended setups

| Scenario | Rule |
| --- | --- |
| Logs and temporary files | Prefix `logs/`, expire current versions 30 days after last modification |
| Buckets with versioning | Entire bucket, expire noncurrent versions 30 days after they become noncurrent, keeping the newest 3, plus remove delete markers |
| Every bucket | Entire bucket, abort multipart uploads 7 days after they start |

## Use the S3 API

| Operation | Description |
| --- | --- |
| GetBucketLifecycleConfiguration | Requires read permission. With no rules, returns 404 `NoSuchLifecycleConfiguration` |
| PutBucketLifecycleConfiguration | Replaces all rules; requires admin permission on the bucket |
| DeleteBucketLifecycle | Deletes all rules; requires admin permission on the bucket |

<Note>
  Sub-user AccessKeys can upload files (which creates versions automatically), delete files without a version ID (which adds a delete marker and requires write permission), list versions, read specific versions, and read the versioning, lifecycle, and Object Lock settings.

  The following require admin permission on the bucket, which sub-user AccessKeys don't have, so do them in the console: enabling and suspending versioning, setting and deleting lifecycle rules, enabling Object Lock and setting the default retention, legal hold, setting compliance retention, permanently deleting by version ID (including items with a version ID in a batch delete), and bypassing governance mode.
</Note>

Supported rule elements: `Filter` (`Prefix`, `Tag`, `ObjectSizeGreaterThan`, `ObjectSizeLessThan`, combined with `And`), `Expiration` (`Days`, `Date`, `ExpiredObjectDeleteMarker`), `NoncurrentVersionExpiration` (`NoncurrentDays`, `NewerNoncurrentVersions`), and `AbortIncompleteMultipartUpload` (`DaysAfterInitiation`).

## Differences from AWS

| Item | S4 behavior |
| --- | --- |
| Storage class transitions | Not supported. Configurations with `Transition` or `NoncurrentVersionTransition` return 400 |
| Run time | One run a day at 03:00 (Beijing time), applying only rules saved before 03:00. There can be up to about a day between expiration and deletion, billed as usual in the meantime |
| Folder objects | Keys ending in `/` are never deleted by rules. Once the files in a folder are deleted, the empty folder is cleaned up automatically (folder objects you created yourself are kept) |
| Past dates | Take effect immediately and keep applying to files written later (same as AWS) |
| Aborting multipart uploads | Skips uploads still receiving parts recently; can't be combined with file size filters |
| Expiration rules with only `Days` | When cleaning up files that have only a delete marker left, the delete marker itself must be `Days` days old |
| Rule ID | Not generated when omitted; returned as-is when read |
| `Filter` syntax | A prefix combined with tag or size conditions must go inside `And`, or the request returns 400 `MalformedXML` (same as AWS) |
| `x-amz-expiration` | Not included in file read and write responses |
| Changed during a run | If a file is rewritten after it was scanned, that item is skipped and handled at most one run later |

## Related

- [Versioning](/bitiful-s4/handbook/versioning)
- [Object Lock](/bitiful-s4/handbook/object-lock)
- [Upload files](/bitiful-s4/handbook/upload)
- [S3 API compatibility](/developer/s3/compatibility)
