Lifecycle Configuration Examples
If you use APIs or SDKs, refer to the XML example. If you use the OBS Console or OBS Browser+, refer to the screenshot.
Specifying a Rule with a Single Filter Condition
Example 1: Applying a lifecycle rule to all objects in a bucket
To apply the rule to all objects in the bucket, leave the prefix blank. Objects will be transitioned to the Archive storage class 100 days after creation.
XML:
1 2 3 4 5 6 7 8 9 10 11 |
<LifecycleConfiguration> <Rule> <ID>sample-rule</ID> <Prefix></Prefix> <Status>Enabled</Status> <Transition> <Days>100</Days> <StorageClass>COLD</StorageClass> </Transition> </Rule> </LifecycleConfiguration> |
Example 2: Specifying a filter by object name prefix
The following lifecycle rule specifies prefix texta/ as the filter. It applies to objects with the texta/ prefix, such as texta/file1.txt and texta/file2.txt.
This rule specifies two actions: transitioning objects to the Infrequent Access storage class 90 days after creation and deleting objects 120 days after creation.
XML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<LifecycleConfiguration> <Rule> <ID>sample-rule</ID> <Status>Enabled</Status> <Prefix>texta/</Prefix> <Transition> <Days>90</Days> <StorageClass>WARM</StorageClass> </Transition> <Expiration> <Days>120</Days> </Expiration> </Rule> </LifecycleConfiguration> |
Example 3: Specifying a filter by object name prefix and deleting the specified objects that was last modified before the specified date
The following lifecycle rule specifies prefix texta/ as the filter. It applies to objects with the texta/ prefix, such as texta/file1.txt and texta/file2.txt.
This rule specifies one action: deleting objects that were last modified before May 30, 2024.
XML:
1 2 3 4 5 6 7 8 9 10 |
<LifecycleConfiguration> <Rule> <ID>sample-rule</ID> <Status>Enabled</Status> <Prefix>texta/</Prefix> <Expiration> <Date>2024-05-30T00:00:00.000Z</Date> </Expiration> </Rule> </LifecycleConfiguration> |
Example 4: Specifying a filter by object name prefix and transitioning the specified objects that was last modified before the specified date
The following lifecycle rule specifies prefix texta/ as the filter. It applies to objects with the texta/ prefix, such as texta/file1.txt and texta/file2.txt.
This rule specifies one action: transitioning objects that were last modified before May 30, 2024 to the Archive storage class.
XML:
1 2 3 4 5 6 7 8 9 10 11 |
<LifecycleConfiguration> <Rule> <ID>sample-rule</ID> <Status>Enabled</Status> <Prefix>texta/</Prefix> <Transition> <Date>2024-05-30T00:00:00.000Z</Date> <StorageClass>COLD</StorageClass> </Transition> </Rule> </LifecycleConfiguration> |
Specifying Multiple Rules
If you want objects to have different lifecycle actions, you can specify multiple rules. The following lifecycle configuration has two rules:
- Rule 1 applies to objects with the texta/ prefix. It directs OBS to transition objects to the Archive storage class 120 days after creation and to delete them 360 days after creation.
- Rule 2 applies to objects with the textb/ prefix. It directs OBS to transition objects to the Infrequent Access storage class 90 days after creation and to delete them 120 days after creation.
XML:
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 |
<LifecycleConfiguration> <Rule> <ID>sample-rule1</ID> <Prefix>texta/</Prefix> <Status>Enabled</Status> <Transition> <Days>120</Days> <StorageClass>COLD</StorageClass> </Transition> <Expiration> <Days>360</Days> </Expiration> </Rule> <Rule> <ID>sample-rule2</ID> <Prefix>textb/</Prefix> <Status>Enabled</Status> <Transition> <Days>90</Days> <StorageClass>WARM</StorageClass> </Transition> <Expiration> <Days>120</Days> </Expiration> </Rule> </LifecycleConfiguration> |
Specifying Multiple Rules with Overlapping Filter Conditions
For details about overlapping prefixes and conflicting actions, see Overlapping Lifecycle Rules.
Example 1: Overlapping prefixes (no conflict)
- Rules: Rule 1 specifies an empty filter (indicating all objects in the bucket). It lets OBS delete all objects 120 days after creation. Rule 2 specifies the typea/ prefix (indicating objects with the typea/ prefix). It lets OBS transition objects to the Archive storage class 90 days after creation.
- Result: There are no conflicting lifecycle actions. Objects with the typea/ prefix are transitioned to the Archive storage class 90 days after creation and then deleted 120 days after creation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<LifecycleConfiguration> <Rule> <ID>sample-rule1</ID> <Prefix></Prefix> <Status>Enabled</Status> <Expiration> <Days>120</Days> </Expiration> </Rule> <Rule> <ID>sample-rule2</ID> <Prefix>typea/</Prefix> <Status>Enabled</Status> <Transition> <Days>90</Days> <StorageClass>COLD</StorageClass> </Transition> </Rule> </LifecycleConfiguration> |
Example 2: Overlapping prefixes resulting in conflicting lifecycle actions
- Rules: Rule 1 specifies an empty filter (indicating all objects in the bucket). It lets OBS delete all objects 90 days after creation. Rule 2 specifies the typea/ prefix (indicating objects with the typea/ prefix). It lets OBS transition objects to the Archive storage class 120 days after creation.
- Result: The lifecycle actions conflict. Such configuration is not allowed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<LifecycleConfiguration> <Rule> <ID>sample-rule1</ID> <Prefix></Prefix> <Status>Enabled</Status> <Expiration> <Days>90</Days> </Expiration> </Rule> <Rule> <ID>sample-rule2</ID> <Prefix>typea/</Prefix> <Status>Enabled</Status> <Transition> <Days>120</Days> <StorageClass>COLD</StorageClass> </Transition> </Rule> </LifecycleConfiguration>
Deleting Fragments
The following lifecycle rule specifies prefix texta/ as the filter. It applies to objects with the texta/ prefix, such as texta/file1.txt and texta/file2.txt. This rule lets OBS delete object fragments 10 days after generation.
1 2 3 4 5 6 7 8 9 10 |
</LifecycleConfiguration> <Rule> <ID>sample-rule</ID> <Prefix>texta/</Prefix> <Status>Enabled</Status> <AbortIncompleteMultipartUpload> <DaysAfterInitiation>10</DaysAfterInitiation> </AbortIncompleteMultipartUpload> </Rule> </LifecycleConfiguration> |
Specifying a Lifecycle Rule for a Versioning-Enabled/Suspended Bucket
Example 1: Periodically transitioning and deleting historical object versions
The following lifecycle rule specifies prefix prefix1/ as the filter. It applies to objects with the prefix1/ prefix, such as prefix1/file1.txt and prefix1/file2.txt.
This rule specifies two lifecycle actions: transitioning historical object versions to the Archive storage class 20 days after generation and deleting them 30 days after generation.
Example 2: Removing expired delete markers
The following lifecycle rule specifies prefix prefix1/ as the filter. It applies to objects with the prefix1/ prefix, such as prefix1/file1.txt and prefix1/file2.txt.
If all versions of an object with the prefix1/ prefix have been deleted and only one expired delete marker remains, this rule lets OBS remove this expired delete marker.
1 2 3 4 5 6 7 8 9 10 |
</LifecycleConfiguration> <Rule> <ID>sample-rule</ID> <Prefix>prefix1/</Prefix> <Status>Enabled</Status> <Expiration> <ExpiredObjectDeleteMarker>true</ExpiredObjectDeleteMarker> </Expiration> </Rule> </LifecycleConfiguration> |
Disabling a Lifecycle Rule
The following configuration disables a lifecycle rule. This rule applies to objects with the texta/ prefix and transitions objects to the Archive storage class 100 days after creation.
XML:
1 2 3 4 5 6 7 8 9 10 11 |
<LifecycleConfiguration> <Rule> <ID>sample-rule</ID> <Status>Disabled</Status> <Prefix>texta/</Prefix> <Transition> <Days>100</Days> <StorageClass>COLD</StorageClass> </Transition> </Rule> </LifecycleConfiguration> |
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