Bucket lifecycle policy

A lifecycle policy lets you automatically manage the removal of objects and object versions in an evroc Object Storage Bucket. You define rules that match objects using filters and specify actions to delete current versions, remove older versions, or abort incomplete multipart uploads.

How lifecycle policies work

A lifecycle policy is a collection of rules. The system evaluates each rule against objects in the bucket. A rule identifies which objects to target using a filter and defines one or more actions to perform on matched objects.

Important: Lifecycle processing runs daily. Once you apply or update a policy, expect a delay of at least one day before the system processes your bucket.

Supported actions

A rule must specify at least one of the following actions:

  • Expire current version — removes the current version of an object or adds a deletion marker in a versioned bucket
  • Expire non-current versions — removes older versions of an object
  • Abort incomplete multipart uploads — aborts in-progress multipart uploads that have been idle for longer than the specified number of days

Filtering objects

If you omit the filter, the rule applies to every object in the bucket. When you define a filter, you can use one or more of the following criteria, which are combined with an AND condition:

  • Prefix — matches objects whose keys start with the specified string
  • Tag — matches objects that have the specified key-value tags attached
  • SizeGreaterThan — matches objects larger than the specified size in bytes
  • SizeLessThan — matches objects smaller than the specified size in bytes

All filter properties you specify must match for the rule to apply.

Configure a lifecycle policy

You apply a lifecycle policy to a bucket using the evroc CLI. Pass the policy as a JSON document to the --lifecycle-policy flag when creating a bucket.

Prerequisites

  • An evroc Object Storage bucket in your project

Add a lifecycle rule using the evroc CLI

  1. Create a JSON file that defines your lifecycle policy:

    {
      "rules": [
        {
          "id": "expire-logs",
          "filter": {
            "prefix": "logs/"
          },
          "expireCurrentVersion": {
            "days": 5
          }
        }
      ]
    }
    
  2. Pass the file path to the --lifecycle-policy flag when you create the bucket:

    evroc storage bucket create my-bucket \
      --lifecycle-policy file://lifecycle-policy.json
    

    Alternatively, provide the JSON inline as a single-line string:

    evroc storage bucket create my-bucket \
      --lifecycle-policy '{"rules":[{"id":"expire-logs","filter":{"prefix":"logs/"},"expireCurrentVersion":{"days":5}}]}'
    
  3. The system validates the policy before applying it.

Example: expire current versions

The following rule removes the current version of objects in the archive/ prefix after 30 days:

evroc storage bucket create data-archive \
  --lifecycle-policy '
    {
      "rules": [
        {
          "id": "archive-expiry",
          "filter": {
            "prefix": "archive/"
          },
          "expireCurrentVersion": {
            "days": 30
          }
        }
      ]
    }'

For this action, you must provide exactly one of date, days, or expireOrphanedDeletionMarkers. If you specify a date, use an ISO 8601 format string.

Example: expire non-current versions

The following rule removes older versions of objects in the backup/ prefix that are at least 7 days old:

evroc storage bucket create data-backup \
  --lifecycle-policy '
    {
      "rules": [
        {
          "id": "purge-backup-versions",
          "filter": {
            "prefix": "backup/"
          },
          "expireNonCurrentVersion": {
            "days": 7
          }
        }
      ]
    }'

For this action, specify exactly one of days or maxNumVersions.

Example: abort incomplete multipart uploads

The following rule aborts incomplete multipart uploads after 3 days:

evroc storage bucket create upload-bucket \
  --lifecycle-policy '
    {
      "rules": [
        {
          "id": "abort-stale-uploads",
          "abortIncompleteMultipart": {
            "days": 3
          }
        }
      ]
    }'

Reference

The following tables describe the structure of the JSON document you pass to the --lifecycle-policy flag.

lifecyclePolicy fields

FieldTypeDescription
rulesarrayThe list of lifecycle rules. You must provide at least one rule.

rules item fields

FieldTypeDescription
idstringA unique identifier for the rule.
disabledbooleanWhen true, the system ignores this rule. Defaults to false.
filterobjectOptional. When present, the rule applies only to objects that match the filter criteria.
abortIncompleteMultipartobjectAborts incomplete multipart uploads older than the specified number of days.
expireCurrentVersionobjectExpires the current version of an object on a specific date or after a set number of days.
expireNonCurrentVersionobjectExpires non-current versions of an object after a set number of days or when a maximum number of versions is exceeded.

filter fields

FieldTypeDescription
prefixstringMatches objects whose keys start with this prefix.
tagarrayMatches objects that have all the specified key-value tags. Each item contains a key and a value.
sizeGreaterThanintegerMatches objects larger than this size in bytes.
sizeLessThanintegerMatches objects smaller than this size in bytes.

abortIncompleteMultipart fields

FieldTypeDescription
daysintegerThe number of days after which the upload is aborted. Must be 1 or greater.

expireCurrentVersion fields

FieldTypeDescription
datestringExpire the object on this date. Format as an ISO 8601 string.
daysintegerExpire the object this many days after creation. Must be 1 or greater.
expireOrphanedDeletionMarkersbooleanExpire orphaned deletion markers.

Important: Exactly one of date, days, or expireOrphanedDeletionMarkers must be specified.

expireNonCurrentVersion fields

FieldTypeDescription
maxNumVersionsintegerRetain at most this many versions. Must be 1 or greater.
daysintegerExpire a non-current version after this many days. Must be 1 or greater.

Important: Exactly one of days or maxNumVersions must be specified.