Application Scenarios
This section describes how to create a lifecycle rule.
Constraints
- A lifecycle rule can use prefixes and tags but cannot use wildcards, suffixes, or regular expressions.
- A bucket can have an unlimited number of lifecycle rules, but the XML file of all its rules cannot exceed 20 KB.
- A maximum of 20 lifecycle rules can be configured for a parallel file system.
- If you want to modify the lifecycle rules of a bucket, you need to add rules. For example, if a bucket has already had Rule 1, you can add Rule 2 by performing the following operations:
- Call GetBucketLifecycle to obtain Rule 1.
- Add Rule 2.
- Call PutBucketLifecycle to update the lifecycle rule to Rule 1 and Rule 2.
If you use OBS Console to update an existing lifecycle rule, you do not need to obtain the rule first. You just need to add a new rule and the new rule then automatically overwrites the existing one. For details, see Configuring a Lifecycle Rule on OBS Console.
Lifecycle Rule Configuration
You can configure lifecycle rules by using OBS Console, APIs, or SDKs.
Using OBS Console
- In the navigation pane of OBS Console, choose Object Storage.
- In the bucket list, click the bucket you want to operate. The Objects page is displayed.
- In the navigation pane, choose Data Management > Lifecycle Rules.
- Click Create.
Figure 1 Creating a lifecycle rule
- Configure a lifecycle rule.
Basic Information:
- Status: Select Enable to enable this lifecycle rule.
- Rule Name: Enter a name to identify your lifecycle rule. The rule name must be no longer than 255 characters.
- Prefix (optional):
- If this field is specified, objects with this prefix will be managed by the lifecycle rule. The prefix cannot start with a slash (/) or contain two consecutive slashes (//), and cannot contain special characters (\:*?"<>|).
- If this field is not specified, all objects in the bucket will be managed by the lifecycle rule.
- Tag (optional): Objects with this tag will be managed by the lifecycle rule. A tag cannot be used as a filter for deleting fragments or expired delete markers.
- A tag key can be 128 characters long at most and consist of letters, digits, and spaces representable in UTF-8, and special characters (_.:=+-@). Each tag key must be unique. A key is case-sensitive and cannot be left blank.
- A tag value can be 255 characters long at most and consist of letters, digits, and spaces representable in UTF-8 and special characters (_.:/=+-@). A tag value is case-sensitive and can be left blank.
Current Version or Historical Version:
- Current Version and Historical Version are two concepts related to Versioning. If versioning is enabled for a bucket, uploading objects with the same name to the bucket creates different object versions. The last uploaded object is called the current version, while those previously uploaded are called historical versions. For more information, see Versioning.
- Either Current Version or Historical Version must be configured, or you can configure both of them.
- Transition to Infrequent Access After (Days): After this number of days since the last update, objects meeting specified conditions will be transitioned to Infrequent Access.
- Transition to Archive After (Days): After this number of days since the last update, objects meeting specified conditions will be transitioned to Archive. If you want to transition objects first to Infrequent Access and then to Archive, ensure that Transition to Archive After (Days) is larger than Transition to Infrequent Access After (Days). If you want to only transition objects to Archive, there is no such a restriction.
- Transition to Deep Archive After (Days): After this number of days since the last update, objects meeting specified conditions will be transitioned to Deep Archive. If you want to transition objects first to Infrequent Access and then to Deep Archive, ensure that Transition to Deep Archive After (Days) is larger than Transition to Infrequent Access After (Days). If you want to transition objects first to Archive and then to Deep Archive, ensure that Transition to Deep Archive After (Days) is larger than Transition to Archive After (Days). If you want to only transition objects to Deep Archive, there is no such a restriction.
- Delete Objects After (Days): After this number of days since the last update, objects meeting specified conditions will be automatically deleted. This number must be an integer larger than that specified for any transition.
- Delete Fragments After (Days): After this number of days since fragment generation, OBS will automatically delete fragments in the bucket.
- Remove Expired Delete Marker: An expired delete marker is the only single delete marker that remains after all historical versions of an object are deleted. This action will remove expired delete markers and help improve the list performance.
- If an object of the current version is configured to be deleted upon expiration, its delete markers will also be deleted. Deleting all current and historical versions of an object will also delete its all delete markers.
- If the current and historical versions of an object are configured to be deleted upon expiration, its all delete markers will also be deleted.
- If Remove Expired Delete Marker takes effect, the expired delete marker will be deleted.
Assume that you stored the following files in OBS on January 7, 2015:
- log/test1.log
- log/test2.log
- doc/example.doc
- doc/good.txt
Then, you stored the following files in OBS on January 10, 2015:
- log/clientlog.log
- log/serverlog.log
- doc/work.doc
- doc/travel.txt
On January 10, 2015, you set the objects prefixed with log to expire one day later. You might encounter the following situations:
- Objects log/test1.log and log/test2.log uploaded on January 7, 2015 might be deleted upon the next system scan. The deletion could happen on January 10, 2015 or January 11, 2015, depending on the time of the system scan.
- For objects log/clientlog.log and log/serverlog.log uploaded on January 10, 2015, each system scan would determine whether one full day had passed since their last update. If any scan determined one full day had passed, those objects would be deleted upon that scan. The deletion might happen on January 11, 2015 or January 12, 2015.
Suppose you configured OBS to transition objects with the log prefix to Infrequent Access and Archive 30 days and 60 days after they are uploaded and delete the objects 100 days after they are uploaded. OBS would perform those actions on log/clientlog.log, log/serverlog.log, log/test1.log, and log/test2.log as you defined.
The object storage time starts from the next UTC 00:00. A lifecycle rule becomes effective at most 24 hours after it is configured. There may be a delay in transitioning objects or deleting expired objects, but it does not exceed 48 hours. If you change an existing lifecycle rule, when the changed rule takes effect will be recalculated.
- Click OK to complete the lifecycle rule configuration.
Configuring a Lifecycle Rule for a Single Object
You can set the time for deleting an object when uploading it. If versioning is enabled, you can set the deletion time for each version of object when uploading it. An object lifecycle rule only affects object versions and not delete markers or fragments.
Unlike setting a lifecycle rule for a bucket, an object lifecycle rule only applies to that specific object. You can only schedule the deletion of the object, and not any storage class transitions. If a bucket lifecycle rule conflicts with an object lifecycle rule, the object lifecycle rule will apply.
OBS allows you to use only APIs and SDKs to set the lifecycle rule for an object.
Using APIs
Specify the x-obs-expires header if you upload an object using PUT (streaming upload) or POST (browser-based upload).
Using SDKs
The following OBS SDKs provides APIs for you to upload objects and configure the expires parameter for object deletion upon expiration: