Basic Structure
Lifecycle configuration uses the XML description method and can be set with one or more lifecycle rules. The basic structure is shown below:
<LifecycleConfiguration>
<Rule>
<ID>**your lifecycle name**</ID>
<Status>Enabled</Status>
<Filter>
<And>
<Prefix>projectA/</Prefix>
<Tag>
<Key>key1</Key>
<Value>value1</Value>
</Tag>
</And>
</Filter>
**transition/expiration actions**
</Rule>
<Rule>
...
</Rule>
</LifecycleConfiguration>
Here, each rule contains the following content:
- ID (optional): You can customize it to describe the content of the rule.
- Status: You can choose to set the rule status to Enabled or Disabled.
- Filter: You can use it to specify the filtering conditions of the objects to be operated.
- Operation: You can specify the operations that need to be performed on objects that match the above description.
- Time: You can specify the number of days (Days) based on the last modification date, or specify the objects that are modified before a specific date (Date).
Rule description
Filter Element
Based on All Objects in the Bucket
Specify an empty filter. This will apply to all objects in the bucket.
<LifecycleConfiguration>
<Rule>
<Filter>
</Filter>
<Status>Enabled</Status>
**transition/expiration actions**
</Rule>
</LifecycleConfiguration>
Based on a Specified Object Key Prefix
Specify a prefix-based filter so that the rule applies only to objects with the specified prefix. For example, you can filter out objects by the prefix logs/.
<LifecycleConfiguration>
<Rule>
<Filter>
<Prefix>logs/</Prefix>
</Filter>
<Status>Enabled</Status>
**transition/expiration actions**
</Rule>
</LifecycleConfiguration>
Based on a Specified Object Tag
Specify some keys and values that match the object tags as the filter to execute the operation only on objects with the specific tag. For example, you can set it to filter out objects by the tag's key=type and value=image:
<LifecycleConfiguration>
<Rule>
<Filter>
<Tag>
<Key>type</Key>
<Value>image</Value>
</Tag>
</Filter>
<Status>Enabled</Status>
**transition/expiration actions**
</Rule>
</LifecycleConfiguration>
Based on Multiple Filters
In Cloud Object Storage (COS), you can use the AND logic to combine multiple filters. For example, you can set it to filter out objects by the prefix logs/ as well as by the object tag's key=type and value=image:
<LifecycleConfiguration>
<Rule>
<Filter>
<And>
<Prefix>logs/</Prefix>
<Tag>
<Key>type</Key>
<Value>image</Value>
</Tag>
</And>
</Filter>
<Status>Enabled</Status>
**transition/expiration actions**
</Rule>
</LifecycleConfiguration>
Operation Element
In a lifecycle rule, you can execute one or more operations on a group of objects that meet the conditions.
Transition Operation
Specify the Transition operation to transition an object from one storage type to another. If versioning is enabled for the bucket, the operation will only be executed on the current version. The shortest transition date can be set to 0 days. For example, you can set to transition an object to ARCHIVE storage type in 30 days:
<Transition>
<StorageClass>ARCHIVE</StorageClass>
<Days>30</Days>
</Transition>
Deletion upon Expiration
Specify the Expiration operation to delete an expired object that meets the rule. If visioning has never been enabled for the bucket, the operation will permanently delete the object. If visioning is enabled for the bucket, the operation will add a DeleteMarker marker to the expired object and set it as the current version. For example, you can set to delete an object in 30 days:
<Expiration>
<Days>30</Days>
</Expiration>
Incomplete Multipart Upload
Specify the AbortIncompleteMultipartUpload operation to maintain multipart upload tasks with the specified UploadId for a period of time before deleting them. Then, these tasks cannot be resumed or searched. For example, you can set to clear an incomplete multipart upload task in 7 days:
<AbortIncompleteMultipartUpload>
<Days>7</Days>
</AbortIncompleteMultipartUpload>
Non-Current Version Object
In a versioning-enabled bucket, transition can only be executed on the latest version, and the expiration operation can only add deletion markers. Therefore, COS provides the following operations for objects of non-current versions:
Specify NoncurrentVersionTransition to transition non-current version objects to another storage type after a specified time. For example, you can set to transition the historical versions to ARCHIVE storage type in 30 days:
<NoncurrentVersionTransition>
<StorageClass>ARCHIVE</StorageClass>
<Days>30</Days>
</NoncurrentVersionTransition>
Specify NoncurrentVersionExpiration to delete non-current version objects after expiration in a specified time. For example, you can set to delete the historical versions in 30 days:
<NoncurrentVersionExpiration>
<Days>30</Days>
</NoncurrentVersionExpiration>
Specify ExpiredObjectDeleteMarker to clear the remaining delete marker when all historical versions of an object key are deleted and the latest version of the object is a DeleteMarker. For example, you can set it to remove the delete marker of an expired object in 31 days:
<ExpiredObjectDeleteMarker>
<Days>31</Days>
</ExpiredObjectDeleteMarker>
Time Element
Based on the Number of Days
Use Days to specify the number of days. The time is calculated based on the last modification time of the object.
- For example, when you set to transition an object to ARCHIVE storage type in 0 days, and the object is uploaded at 23:55:00 GMT+8 on January 1, 2018. Then it will be added to the processing queue for storage type transition at 00:00:00 GMT+8 on January 2, 2018 and transitioned by 23:59:59 GMT+8 on January 2, 2018.
- For example, when you set to delete an object after expiration in 1 day, and the object is uploaded at 23:55:00 GMT+8 on January 1, 2018. Then it will be added to the processing queue for deletion after expiration at 00:00:00 GMT+8 on January 3, 2018 and deleted by 23:59:59 GMT+8 on January 3, 2018.
Based on a Specific Date
Use Date to specify the date. The operation will be executed on all objects that meet the filtering condition on the specified date. Currently, only GMT+8 time zone is supported. The time is set to 00:00 GMT+8 in the ISO8601 format.
For example, January 1, 2018, is described as: 2018-01-01T00:00:00+08:00.