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>
 <Tag><Key>xx</Key><Value>1</Value></Tag>
 <Status>Enabled</Status>
 <Transition>
   <Days>60</Days>
   <StorageClass>Archive</StorageClass>
</Transition>
</Rule>
</LifecycleConfiguration>        
The following items describe the three lifecycle rules in the preceding example:
  • 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 whose tag is xx:1 and that were last modified 60 days ago to Archive.

The following sections describe the elements, such as the ID and operation elements, that you can configure in the configuration file of lifecycle rules for objects.

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, which can be Enabled or Disabled. Only 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 applies to all or some objects in a bucket.

Not

The Not element specifies the prefix in the names of objects and the tags of objects to which you do not want the lifecycle rule to apply when you use the lifecycle rule to process the objects whose names contain a specific prefix and that have specific tags.

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 that has versioning disabled
    Operation Description
    Transition The conversion of the storage class of objects that match the lifecycle rule 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 class of an object.
    Expiration The delete operation that you want OSS to perform on the objects that match the lifecycle rule when the objects expire based on the date or validity period that is specified in the lifecycle rule.
  • Bucket that has versioning enabled

    The following tables describe the elements that can be specified in lifecycle rules for objects in versioned buckets. Versioned buckets can be versioning-enabled or versioning-suspended.

    • Delete or storage class conversion operation on the current version of objects
      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 by 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.
          Notice
          • 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 with no object version specified, 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 conversion of the storage class of objects that match the lifecycle rule when the objects expire based on the date or validity period that is specified in the lifecycle rule.
    • Delete or storage class conversion operation on the previous versions of objects
      Operation Description Associated child element
      NoncurrentVersionExpiration The delete operation that you want OSS to perform on the previous versions of the objects that match the lifecycle rule when the previous versions expire. The <NoncurrentDays> child element specifies the number of days from when the current versions became previous versions to when the previous versions are permanently deleted.
      Note For example, a version was the current version of an object. 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 conversion of the storage class of objects that match the lifecycle rule when the previous versions of the objects expire.
      • The <NoncurrentDays> child element specifies the number of days from when the current versions became previous versions to 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.