This topic describes the elements that you can configure in the configuration file of lifecycle rules for objects.
The configuration file of lifecycle rules for objects is in the XML format. Example:
<LifecycleConfiguration>
<Rule>
<ID>rule1</ID>
<Prefix>logs/</Prefix>
<Status>Enabled</Status>
<Filter>
<Not>
<Prefix>logs1/</Prefix>
<Tag><Key>key1</Key><Value>value1</Value></Tag>
</Not>
</Filter>
<Expiration>
<Days>10</Days>
</Expiration>
</Rule>
<Rule>
<ID>rule2</ID>
<Prefix>doc/</Prefix>
<Status>Disabled</Status>
<Expiration>
<CreatedBeforeDate>2017-12-31T00:00:00.000Z</CreatedBeforeDate>
</Expiration>
</Rule>
<Rule>
<ID>rule3</ID>
<Prefix>logs2/</Prefix>
<Tag><Key>xx</Key><Value>1</Value></Tag>
<Status>Enabled</Status>
<Transition>
<Days>60</Days>
<StorageClass>Archive</StorageClass>
</Transition>
</Rule>
</LifecycleConfiguration>
- The first rule is used to delete the objects whose names contain the logs/ prefix and that were last modified 10 days ago. The objects whose names contain the logs1/ prefix and whose tag is key1:value1 are not deleted.
- The second rule is used to delete the objects whose names contain the doc/ prefix and that were last modified before December 31, 2017. This rule is disabled and does not take effect.
- The third rule is used to convert the storage class of the objects that meet the following conditions to Archive: The object names contain the logs2/ prefix, the tag of the objects is xx:1, and the objects were last modified 60 days ago.
The following sections describe the elements that you can configure in the configuration file of lifecycle rules for objects. The elements include the ID and operation elements.
ID
The ID element specifies the ID of the lifecycle rule that is configured for a bucket. The ID of a lifecycle rule can be up to 255 bytes in length. If you do not configure this element or you leave this element empty, Object Storage Service (OSS) automatically generates a unique ID for the lifecycle rule.
Status
The Status element specifies the status of the lifecycle rule. The status can be Enabled or Disabled. Only the rules for which the value of the Status element is Enabled take effect.
Prefix
The Prefix element specifies the object name prefix based on which the lifecycle rule is applied to all or some objects in a bucket.
Filter
The Filter element specifies the filter condition of a lifecycle rule. Objects that meet all the conditions that are specified in the Filter element match the rule.
Not
When you use the lifecycle rule to process objects whose names contain a specific prefix and that have specific tags, you may want to skip specific objects. In this case, you can specify the name prefixes and tags of the objects that you want to skip in the Not element.
Time
- Date
The <CreatedBeforeDate> child element specifies an absolute date. All objects that were last modified before the date are deleted, or the storage class of the objects that were last modified before the date is converted.
- Days
The <Days> child element specifies the validity period of the objects after the objects were last modified. After the validity period ends, the objects are deleted, or the storage class of the objects is converted.
Operation
You can configure one or more operation elements in a lifecycle rule for objects that match the lifecycle rule. Then, OSS performs the specified operations on the objects when the objects expire. The effect of the operations varies based on the versioning status of the bucket in which the objects are stored. The following tables describe how the versioning status of the bucket affects the operation that is specified in the lifecycle rule for the objects.
- Bucket for which versioning is disabled
Operation Description Transition The storage class of objects that match the lifecycle rule is converted when the objects expire based on the date or validity period that is specified in the lifecycle rule. For more information about the storage classes that you can specify in lifecycle rules, see Configure lifecycle rules to automatically convert the storage classes of objects. Expiration The objects that match the lifecycle rule are deleted when the objects expire based on the date or validity period that is specified in the lifecycle rule. - Bucket for which versioning is enabled
The following tables describe the elements that can be specified in lifecycle rules for objects in versioned buckets. Versioned buckets include the buckets for which versioning is enabled and the buckets for which versioning is suspended:
- Delete or storage class conversion operation on the current version of an object
Operation Description Expiration The operation performed on an expired object varies based on whether the current version of the object is a delete marker. - If the current version of the object is not a delete marker, OSS processes the version
based on the following rules:
- If versioning is enabled for the bucket that stores the object, OSS inserts a delete marker that has a unique version ID. Then, the current version of the object is replaced with the inserted delete marker.
- If versioning is suspended for the bucket that stores the object, OSS inserts a delete marker whose version ID is null. The inserted delete marker overwrites the current version of the object whose version ID is null to ensure that only one version of the object whose version ID is null exists.
- If the current version of the object is a delete marker, OSS processes the version
based on the following rules:
- If one or more previous versions of the object exist, no operation that is specified in the lifecycle rule is triggered.
- If only one version of the object exists, the delete marker is removed when the delete
marker expires based on the date or validity period that is specified in the lifecycle
rule or when the ExpiredObjectDeleteMarker child element is set to true in the lifecycle rule.
Important
- If the Expiration operation of a lifecycle rule that is configured for an object is triggered to delete the current version of the object or a delete operation is initiated without a specified object version, the current version of the object becomes a previous version of the object. If the Expiration operation of a lifecycle rule that is configured for an object is triggered to delete a previous version of the object or a delete operation is initiated on a specified previous version of the object, the previous version of the object is permanently deleted, and only the expired delete marker of the object is retained.
- You cannot configure the ExpiredObjectDeleteMarker child element and specify a tag in a lifecycle rule at the same time.
Transition The storage class of the current version of the objects that match the lifecycle rule is converted when the objects expire based on the date or validity period that is specified in the lifecycle rule. - If the current version of the object is not a delete marker, OSS processes the version
based on the following rules:
- Delete or storage class conversion operation on the previous versions of objects
Operation Description Associated child element NoncurrentVersionExpiration The objects that match the lifecycle rule are deleted when the previous versions expire based on the date or validity period that is specified in the lifecycle rule. The <NoncurrentDays> child element specifies the number of days from the time when the current versions became previous versions to the time when the previous versions are permanently deleted. Note For example, a version was the current version of an object before May 1, 2019. On May 1, 2019, the PutObject operation was called, and this version became a previous version. In the NoncurrentVersionExpiration element, <NoncurrentDays> is set to 3. On May 4, 2019, the version was permanently deleted. Each time the PutObject operation is called for an object, the current version of the object becomes the most recent previous version. The uploaded version becomes the current version of the object. OSS determines when a version becomes a previous version based on the time when the next version is created.NoncurrentVersionTransition The storage class of objects that match the lifecycle rule is converted when the previous versions of the objects expire based on the date or validity period that is specified in the lifecycle rule. - The <NoncurrentDays> child element specifies the number of days from the time when the current versions became previous versions to the time when the storage class of the objects is converted.
- The <StorageClass> child element specifies the storage class to which the storage class of the objects is converted.
- Delete or storage class conversion operation on the current version of an object