Configuring Bucket Lifecycle Rules
Functions
This operation configures lifecycle rules that can delete or migrate objects from a bucket at a specified time. Typical application scenarios:
- Delete periodically uploaded files. Some files uploaded periodically need only to be retained for only one week or one month.
- Delete files that are frequently accessed within a certain period of time but are seldom accessed afterward. You can archive these files and then schedule the time for deletion.
- The minimum time for the transition of the bucket storage to Infrequent Access or Archive can be configured. The value ranges from 24 to 8640.
You can perform this operation to create or update the lifecycle configuration of a bucket.
- Expired objects deleted based on a lifecycle rule cannot be recovered.
- Multi-AZ storage is not available to the Archive or Deep Archive storage class. For this reason, buckets or objects with multi-AZ redundancy cannot be transitioned to the Archive or Deep Archive storage class based on a lifecycle rule.
To perform this operation, you must have the PutLifecycleConfiguration permission. By default, only the bucket owner can perform this operation. The bucket owner can grant the permission to other users by configuring the bucket policy or user policy.
The lifecycle configuration enables OBS to delete objects and transition object storage classes at a scheduled time. To prevent a user from doing so, the following permissions granted to the user must be revoked:
- DeleteObject
- DeleteObjectVersion
- PutLifecycleConfiguration
If you want to forbid a user to set the bucket lifecycle configuration, revoke the PutLifecycleConfiguration permission from the user.
Request Syntax
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
PUT /?lifecycle HTTP/1.1 Host: bucketname.obs.region.myhuaweicloud.com Content-Length: length Date: date Authorization: authorization Content-SHA256: SHA256 <?xml version="1.0" encoding="UTF-8"?> <LifecycleConfiguration> <Rule> <ID>id</ID> <Prefix>prefix</Prefix> <Status>status</Status> <Expiration> <Days>days</Days> </Expiration> <NoncurrentVersionExpiration> <NoncurrentDays>days</NoncurrentDays> </NoncurrentVersionExpiration> <Transition> <Days>30</Days> <StorageClass>WARM</StorageClass> </Transition> <Transition> <Days>60</Days> <StorageClass>COLD</StorageClass> </Transition> <NoncurrentVersionTransition> <NoncurrentDays>30</NoncurrentDays> <StorageClass>WARM</StorageClass> </NoncurrentVersionTransition> <NoncurrentVersionTransition> <NoncurrentDays>60</NoncurrentDays> <StorageClass>COLD</StorageClass> </NoncurrentVersionTransition> <AbortIncompleteMultipartUpload> <DaysAfterInitiation>10</DaysAfterInitiation> </AbortIncompleteMultipartUpload> </Rule> </LifecycleConfiguration> |
Request Parameters
This request contains no parameters.
Request Headers
Table 1 lists the request header.
Request Elements
In this request body, you need to specify the lifecycle configuration in XML format. Table 2 describes the specific configuration elements.
- If the versioning of a bucket is enabled or suspended, you can set NoncurrentVersionTransition or NoncurrentVersionExpiration to control the lifecycle of historical object versions. The lifecycle of a historical version depends on the time when it becomes a historical one (time when the version is replaced by a new version) and the value of NoncurrentDays. If NoncurrentDays is set to 1 in an object deletion scenario, an object version will be deleted one day after it becomes historical. If the version V1 of object A is created on the first date of a month and new version V2 is uploaded on the fifth date of the month, V1 becomes a historical version. At 00:00 on the seventh date of the month, V1 will expire. If an object version does not meet the deletion conditions, but NoncurrentDays is set to 1 and StorageClass is set to WARM, the version transitions to the Infrequent Access storage class one day after it has become a historical version. For example, the V1 version of object A is created on the first day of a month, and its new version V2 is uploaded on the fifth day of the month. Then V1 becomes a historical version. One day later, that is, at 0 o'clock of the seventh day, V1 transitions to the Infrequent Access storage class. The deletion or transition of the object after the expiration time may be delayed. The delay is within 48 hours.
- Objects are processed according to the following procedures, if their latest versions meet the expiration rule and versioning is enabled or suspended for the bucket.
- Versioning enabled:
If the latest object version is not a delete marker, a new delete marker will be inserted for the object.
If the latest object version is a delete marker and is the only version of the object, this latest version will be deleted.
If the object of the latest version has the DeleteMarker and the object has other versions, all versions of the object remain unchanged.
- Versioning suspended:
If the latest version of the object does not have the DeleteMarker and is not the null version, the object generates a new DeleteMarker for the null version.
If the latest version of the object does not have the DeleteMarker but is the null version, this null version is overwritten by a new DeleteMarker generated for the null version.
If the latest object version is a delete marker and is the only version of the object, this latest version will be deleted.
If the object of the latest version has the DeleteMarker and the object has other versions, all versions of the object remain unchanged.
- Versioning enabled:
- The following lists the processing when the versioning is enabled or suspended for a bucket and objects of the latest versions meet the transition rules:
- If the latest version of the object has the DeleteMarker, the storage class of this version will not be transitioned.
- If the latest version of the object does not have the DeleteMarker and meets the transition rule, the storage class of this version will be transitioned.
Name |
Description |
Mandatory |
---|---|---|
Date |
Specifies that OBS executes lifecycle rules for objects before the specified date. The date must be compliant with the ISO8601 format, and the time must be compliant with the UTC format of 00:00:00. For example, 2018-01-01T00:00:00.000Z indicates that objects whose last modification time is earlier than 2018-01-01T00:00:00.000Z are deleted or transitioned to another storage class. Objects whose last modification time is equal to or later than the specified time are not deleted or transitioned to another storage class. Type: string Parent: Expiration, Transition |
Required if the Days element is absent. |
Days |
Specifies the number of days (since the latest update to the latest object version) after which the lifecycle rule takes effect. Type: integer Parent: Expiration, Transition |
Required if the Date element is absent. |
StorageClass |
The storage class to which the object is transitioned. Type: string Value options: WARM, COLD, DEEP_ARCHIVE Parent: Transition, NoncurrentVersionTransition |
Required if the Transition or NoncurrentVersionTransition element is present. |
Transition |
Transition time and the object storage class after transition (valid only for the latest object version). Type: XML Child: Date or Days, StorageClass Parent: Rule |
Required if the NoncurrentVersionTransition, Expiration, AbortIncompleteMultipartUpload, or NoncurrentVersionExpiration element is absent. |
Expiration |
Container for the object expiration rule (only applicable to the latest versions of objects). Type: XML Child: Date or Days Parent: Rule |
Required if Transition, NoncurrentVersionTransition, AbortIncompleteMultipartUpload, or NoncurrentVersionExpiration is absent. |
ID |
Unique identifier of a rule. The value can contain a maximum of 255 characters. Type: string Parent: Rule |
No |
LifecycleConfiguration |
Container for lifecycle rules. You can add multiple rules. The total size of the rules cannot exceed 20 KB. Type: XML Child: Rule Parent: none |
Yes |
NoncurrentDays |
Number of days when the specified rule takes effect after the object becomes a historical version (only applicable to an object's historical version). Type: integer Parent: NoncurrentVersionExpiration, NoncurrentVersionTransition |
Required if the NoncurrentVersionExpiration or NoncurrentVersionTransition element is present. |
NoncurrentVersionTransition |
Transition time of historical object versions and the object storage class after transition. Type: XML Child: NoncurrentDays, StorageClass Parent: Rule |
Required if the Transition, Expiration, AbortIncompleteMultipartUpload, or NoncurrentVersionExpiration element is absent. |
NoncurrentVersionExpiration |
Container for the expiration time of objects' historical versions. If versioning is enabled or suspended for a bucket, you can set NoncurrentVersionExpiration to delete historical versions of objects that match the lifecycle rule (only applicable to the historical versions of objects). Type: XML Child: NoncurrentDays Parent: Rule |
No |
AbortIncompleteMultipartUpload |
Container for specifying when the not merged parts (fragments) in an incomplete upload will be deleted. Type: XML Child: DaysAfterInitiation Parent: Rule |
Required if the Transition, Expiration, NoncurrentVersionExpiration, or NoncurrentVersionTransition element is absent. |
DaysAfterInitiation |
Specifies the number of days since the initiation of an incomplete multipart upload that OBS will wait before deleting the not merged parts (fragments) of the upload. Type: integer Parent: AbortIncompleteMultipartUpload |
Required if the AbortIncompleteMultipartUpload element is present. |
Prefix |
Object name prefix that identifies one or more objects to which the rule applies. Type: string Parent: Rule Constraints:
|
Yes |
Rule |
Container for a specific lifecycle rule. Type: container Parent: LifecycleConfiguration |
Yes |
Status |
Indicates whether the rule is enabled. Type: string Parent: Rule Value options: Enabled, Disabled |
Yes |
Response Syntax
1 2 3 |
HTTP/1.1 status_code Date: date Content-Length: length |
Response Headers
The response to the request uses common headers. For details, see Table 1.
Response Elements
This response contains no elements.
Error Responses
No special error responses are returned. For details about error responses, see Table 2.
Sample Request
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
PUT /?lifecycle HTTP/1.1 User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Accept: */* Date: WED, 01 Jul 2015 03:05:34 GMT Authorization: OBS H4IPJX0TQTHTHEBQQCEC:DpSAlmLX/BTdjxU5HOEwflhM0WI= Content-SHA256: ogX9qClMrVJUBiUSIKDFM0qO41jJM0I5SCN55/OtMyI= Content-Length: 919 <?xml version="1.0" encoding="utf-8"?> <LifecycleConfiguration> <Rule> <ID>delete-2-days</ID> <Prefix>test/</Prefix> <Status>Enabled</Status> <Expiration> <Days>70</Days> </Expiration> <NoncurrentVersionExpiration> <NoncurrentDays>70</NoncurrentDays> </NoncurrentVersionExpiration> <Transition> <Days>30</Days> <StorageClass>WARM</StorageClass> </Transition> <Transition> <Days>60</Days> <StorageClass>COLD</StorageClass> </Transition> <NoncurrentVersionTransition> <NoncurrentDays>30</NoncurrentDays> <StorageClass>WARM</StorageClass> </NoncurrentVersionTransition> <NoncurrentVersionTransition> <NoncurrentDays>60</NoncurrentDays> <StorageClass>COLD</StorageClass> </NoncurrentVersionTransition> <AbortIncompleteMultipartUpload> <DaysAfterInitiation>10</DaysAfterInitiation> </AbortIncompleteMultipartUpload> </Rule> </LifecycleConfiguration> |
Sample Response
1 2 3 4 5 6 |
HTTP/1.1 200 OK Server: OBS x-obs-request-id: BF26000001643670AC06E7B9A7767921 x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSvK6z8HV6nrJh49gsB5vqzpgtohkiFm Date: WED, 01 Jul 2015 03:05:34 GMT Content-Length: 0 |
Sample Request: Transitioning the Objects' Storage Class Only
PUT /?lifecycle HTTP/1.1 Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4= User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Date: WED, 01 Jul 2015 02:37:22 GMT Content-Type: application/xml Content-MD5: b67aDumlm/b+5iev6+sRYw== <LifecycleConfiguration> <Rule> <ID>delete-2-days</ID> <Prefix>test/</Prefix> <Status>Enabled</Status> <Transition> <Days>30</Days> <StorageClass>WARM</StorageClass> </Transition> <Transition> <Days>60</Days> <StorageClass>COLD</StorageClass> </Transition> </Rule> </LifecycleConfiguration>
Sample Response: Transitioning the Objects' Storage Class Only
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSZbDadL1f7fYU44bvRLvc0l6D10+wzG x-obs-request-id: 0000018A2BCBB3ABD3046B99E3ED2E30 Server: OBS Content-Length: 0 Date: WED, 01 Jul 2015 02:37:22 GMT
Sample Request: Deleting Expired Objects Only
PUT /?lifecycle HTTP/1.1 Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4= User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Date: WED, 01 Jul 2015 02:37:22 GMT Content-Type: application/xml Content-MD5: tt0IizQ7YSTFtMJ3sie6qA== <LifecycleConfiguration> <Rule> <ID>delete-2-days</ID> <Prefix>test/</Prefix> <Status>Enabled</Status> <Expiration> <Days>70</Days> </Expiration> </Rule> </LifecycleConfiguration>
Sample Response: Deleting Expired Objects Only
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSfpG6nArWY7cM7rB3+GbvO13XJPx9g4 x-obs-request-id: 0000018A2BD6BB02D30426F6E4A1FBA2 Server: OBS Content-Length: 0 Date: WED, 01 Jul 2015 02:37:22 GMT
Sample Request: Transitioning the Objects' Storage Class and Then Deleting the Objects
PUT /?lifecycle HTTP/1.1 Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4= User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Date: WED, 01 Jul 2015 02:37:22 GMT Content-Type: application/xml Content-MD5: 9CJYqNUbXEVhhawEx0ICRw== <LifecycleConfiguration> <Rule> <ID>delete-2-days</ID> <Prefix>test/</Prefix> <Status>Enabled</Status> <Expiration> <Days>70</Days> </Expiration> <Transition> <Days>30</Days> <StorageClass>WARM</StorageClass> </Transition> <Transition> <Days>60</Days> <StorageClass>COLD</StorageClass> </Transition> </Rule> </LifecycleConfiguration>
Sample Response: Transitioning the Objects' Storage Class and Then Deleting the Objects
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSMYkLcGTyUsgSJe2Rdsg2P8JwMsJV6n x-obs-request-id: 0000018A2BDA0816D2877F5D5622F0BA Server: OBS Content-Length: 0 Date: WED, 01 Jul 2015 02:37:22 GMT
Sample Request: Deleting Historical Object Versions and Delete Markers
PUT /?lifecycle HTTP/1.1 Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4= User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Date: WED, 01 Jul 2015 02:37:22 GMT Content-Type: application/xml Content-MD5: SGAUB+2hLUAWV5IJ69xU+Q== <LifecycleConfiguration> <Rule> <ID>delete-2-days</ID> <Prefix>test/</Prefix> <Status>Enabled</Status> <NoncurrentVersionExpiration> <NoncurrentDays>70</NoncurrentDays> </NoncurrentVersionExpiration> </Rule> </LifecycleConfiguration>
Sample Response: Deleting Historical Object Versions and Delete Markers
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCSZbDadL1f7fYU44bvRLvc0l6D10+wzG x-obs-request-id: 0000018A2BCBB3ABD3046B99E3ED2E30 Server: OBS Content-Length: 0 Date: WED, 01 Jul 2015 02:37:22 GMT
Sample Request: Deleting Fragments
PUT /?lifecycle HTTP/1.1 Authorization: OBS H4IPJX0TQTHTHEBQQCEC:iqSPeUBl66PwXDApxjRKk6hlcN4= User-Agent: curl/7.29.0 Host: examplebucket.obs.region.myhuaweicloud.com Date: WED, 01 Jul 2015 02:37:22 GMT Content-Type: application/xml Content-MD5: PBgGafte2ACjUwYxdJA47Q== <LifecycleConfiguration> <Rule> <ID>delete-2-days</ID> <Prefix>test/</Prefix> <Status>Enabled</Status> <AbortIncompleteMultipartUpload> <DaysAfterInitiation>10</DaysAfterInitiation> </AbortIncompleteMultipartUpload> </Rule> </LifecycleConfiguration>
Sample Response: Deleting Fragments
x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCTlN+glNMVGtTicAnVXkTVDjR5xKSLuH x-obs-request-id: 0000018A2BE86742D2C6989CA79E136C Server: OBS Content-Length: 0 Date: WED, 01 Jul 2015 02:37:22 GMT
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot