Lifecycle Management

Lifecycle management for OBS includes periodically deleting objects from buckets and transitioning between object storage classes based on pre-defined rules.

Figure 1 Lifecycle management

Application Scenario

You may configure lifecycle management rules to perform the following:
  • Periodically deleting files that are only meant to be retained for specified periods of time
  • Transitioning documents that are seldom accessed to the Infrequent Access or Archive storage class or deleting them
  • Storing various types of data in OBS for archive purposes, such as digital media, financial and medical records, original genome sequence data, long-term database backup, and data that must be retained for regulatory compliance.
  • Scheduling the deletion of all files from a bucket. Deleting objects manually is time-consuming, and only a limited number of objects can be deleted at a time.

You can define lifecycle rules for identifying objects and manage lifecycles of the objects based on the rules.

Objects that are no longer frequently accessed can be transitioned to Infrequent Access or Archive, reducing your costs. In short, transition basically means that the object storage class is altered without copying the object. You can also manually change the storage class of an object on the Objects page. For details, see Uploading a File.

Lifecycle configuration can be added to a bucket with versioning enabled or disabled. By default, versioning is disabled. You can enable it. If versioning is enabled for a bucket, the bucket will maintain the current object version and zero or more non-current object versions. You can reduce object storage costs using versioning and lifecycle rules. The predefined lifecycle configuration actions can facilitate management over the lifecycle of the current object versions and non-current object versions.

Precautions

There is no limit on the number of lifecycle rules in a bucket, but the total size of JSON descriptions about all lifecycle rules in a bucket cannot exceed 20 KB.

Restrictions on object storage class transition:

  • Lifecycle rules can only transition objects from the Standard storage class to the Infrequent Access storage class. Manual operations are required to transition objects from the Infrequent Access storage class to the Standard storage class.
  • Objects can only be transitioned from the Standard or Infrequent Access storage class to Archive storage class. If you want to transition objects from the Archive storage class to the Standard or Infrequent Access storage class, you need to restore objects from the Archive storage class first and then manually transition the storage class.

\

OBS provides the Expiration action which allows you to set the expiration time for objects. In addition, for buckets with versioning enabled, OBS provides the NoncurrentVersionExpiration operation which allows you to set the expiration time for non-current object versions.

For buckets with versioning disabled, the Expiration action allows you to delete the expired objects permanently.

If versioning control is enabled (or suspended) for a bucket, the Expiration action will logically delete the current version of an object by creating a delete marker for the current version and recognizing the delete marker as the new current version. The NoncurrentVersionExpiration action deletes objects of non-current versions permanently.

Beside buckets, you can also configure the expiration time for objects during object uploads. The expiration time of objects prevails against that of buckets.

After an object expires, OBS adds the object to the deletion queue and delete it asynchronously. This may cause the deletion time to be later than the expiration time. After an object expires, you will not be charged for the related storage duration fee.

To query the planned expiration time of an object, you can call the GET object API or HEAD object API. These APIs return response headers that provide expiration information about the object.

After a lifecycle rule is modified, the modification does not apply to the objects that have already met the configured conditions. For example, the original lifecycle rule causes objects meeting the configured conditions expire and then be deleted after they are stored for one day. Under this rule, the objects uploaded on January 1, 2021 will be deleted on January 3, 2021. On January 3, 2021, if you change the lifecycle rule to delete objects after they are stored for seven days, the objects uploaded on January 1, 2021 will still be deleted on January 3, 2021, but this modification will apply to those uploaded on and after January 2, 2021.

Lifecycle Rules

Lifecycle rules have the following key elements:

  • Policy: Configure a lifecycle rule that takes effect on specified objects.
    • By prefix: You can specify an object name prefix, so the lifecycle rule will take effect on objects share the same prefix.
    • Entire bucket: You can specify an entire bucket, so the lifecycle rule will take effect on all objects in the bucket.
  • Time: a scheduled time when object storage class is transitioned
    You can specify the number of days after which objects that have been last updated and meet specified conditions are automatically transitioned to Infrequent Access, Archive, or expire and are then automatically deleted.
    • Transition to Infrequent Access: You can specify the number of days after which objects that have been last updated and meet specified conditions are automatically transitioned to Infrequent Access.
    • Transition to Archive: You can specify the number of days after which objects that have been last updated and meet specified conditions are automatically transitioned to Archive.
    • Deleted upon expiration: You can specify the number of days after which objects that have been last updated and meet specified conditions are automatically deleted.
    The lifecycle rule time has the following restrictions:
    • If only one transition is involved, the time should be at least one day later.
    • If multiple transitions are involved, the latter transition should be at least one day longer than the former transition.

      For example, if you want a lifecycle rule to change object storage class and delete expired objects, you can set the transition time to 23 days later and the deletion time to at least 24 days later.

      The minimum billing period is 30 days for Infrequent Access storage and 90 days for Archive storage. If objects are deleted by a lifecycle rule before they have been stored for this minimum period, you will still be charged for the full period (30 or 90 days, depending on the service).

      Example: You upload an object to the Standard storage class, and no other operation is performed on the object. The bucket, where the object resides, has a lifecycle rule that will change object storage class from Standard to Infrequent Access three days later, then from Infrequent Access to Archive, and finally delete objects as they expire seven days later. In this case, you will be charged for three days of Standard storage, 30 days of Infrequent Access storage, and 90 days of Archive storage.

Lifecycle Configuration Elements

You can set the lifecycle configuration format to XML. The configuration contains one or more lifecycle rules.

Each rule consists of the following contents:

  • Metadata, specifying the rule ID and whether the rule is enabled or disabled. If the rule is disabled, OBS does not perform actions specified in the rule.
  • Filtering criteria, identifying objects on which lifecycle rules are applied. You can set the object name prefix to be the filtering criteria.
  • When (a date or a time period) will one transition or expiration action be performed on objects in the lifecycle.

Configuration examples:

Example 1: Lifecycle configuration of a bucket with versioning disabled

By default, versioning is disabled for buckets. Each object has only one version.

Assume that versioning is disabled for your bucket, and you want that objects whose name starts with documents/ transition from Standard storage class to Infrequent Access storage class 30 days after they are uploaded, then from Infrequent Access storage class to Archive storage class 60 days after they are uploaded, and finally be deleted one year after they are uploaded. To achieve these, you can add the following lifecycle configuration for your bucket. This lifecycle rule includes two operations (Transition and Expiration). This rule applies to objects whose key prefix is documents (specified in the Prefix element).

<LifecycleConfiguration> 
    <Rule> 
        <ID>sample-rule</ID> 
        <Prefix>documents/</Prefix> 
        <Status>Enabled</Status> 
        <Expiration> 
             <Days>365</Days> 
        </Expiration> 
        <Transition>  
             <Days>30</Days> 
             <StorageClass>WARM</StorageClass>
        </Transition>  
        <Transition>  
             <Days>60</Days>  
             <StorageClass>COLD</StorageClass>  
        </Transition> 
    </Rule> 
</LifecycleConfiguration>

Example 2. Lifecycle configuration of a bucket with versioning enabled

You can enable versioning for buckets. If versioning is enabled for a bucket, the bucket will retain the current object version and its non-current object versions. For details, see Versioning. Versioning control enables you to maintain the history records of objects and lifecycle management allows you to control the retention of object versions as well as the storage class transition.

For a bucket with versioning enabled, lifecycle configuration provides multiple predefined actions that can be used to manage non-current object versions. In this example, the lifecycle configuration has a rule that specifies two operations (NoncurrentVersionTransition and NoncurrentVersionExpiration) for objects whose key prefix is logs/. The NoncurrentVersionTransition action transitions objects to Infrequent Access and then to Archive 30 days and 60 days respectively after they become non-current versions. The NoncurrentVersionExpiration action permanently deletes objects 180 days after they become non-current versions.

<LifecycleConfiguration> 
    <Rule> 
        <ID>sample-rule</ID> 
        <Prefix>logs/</Prefix> 
        <Status>Enabled</Status>    
        <NoncurrentVersionExpiration>      
            <NoncurrentDays>180</NoncurrentDays>     
        </NoncurrentVersionExpiration> 
        <NoncurrentVersionTransition>  
            <NoncurrentDays>30</NoncurrentDays>  
            <StorageClass>WARM</StorageClass>  
        </NoncurrentVersionTransition>  
        <NoncurrentVersionTransition>  
            <NoncurrentDays>60</NoncurrentDays>  
            <StorageClass>COLD</StorageClass>  
        </NoncurrentVersionTransition> 
    </Rule> 
</LifecycleConfiguration>

You can use the predefined NoncurrentVersionTransition and NoncurrentVersionExpiration actions to manage non-current versions in your bucket.

Generally, each lifecycle rule consists of the following parts:

  • Metadata: specifying the rule ID (<ID> element) and whether the rule is enabled or disabled (<Status> element). If the rule is disabled, OBS does not perform actions specified in the rule.
  • Prefix (<Prefix> element), which identifies objects to which the rule applies.
  • Actions that you want to perform on the specified objects (such as NoncurrentVersionTransition and NoncurrentVersionExpiration mentioned in the previous example). Each action includes the date when or time period after which the action will be performed.

Elements in the lifecycle configuration rule are described as follows:

  • Element ID

    One lifecycle configuration can have a maximum of 1000 rules. Each rule has a unique ID.

  • Element Status

    The value can be Enabled or Disabled. If a rule is disabled, OBS does not perform any actions defined in the rule.

  • Element Prefix

    A lifecycle rule applies to one or more objects with the name prefix specified in the rule. Suppose you have the following objects:

    • logs/day1
    • logs/day2
    • logs/day3
    • ExampleObject.jpg

      If you set Prefix to ExampleObject.jpg, the rule applies only to object ExampleObject.jpg. If you set Prefix to logs/, the rule applies to the objects whose name starting with logs/. If you leave Prefix null, the rule applies to all objects in your bucket.

  • Element Action

    You can specify predefined actions in the lifecycle rule to perform them on your buckets in the lifecycle. The predefined actions include Transition, Expiration, NoncurrentVersionTransition, and NoncurrentVersionExpiration. The action effect depends on the status of versioning control of a bucket.

    By default, versioning is disabled for buckets. You can enable bucket versioning, so that each object has a current version and may have one or more non-current versions. As well, you can disable versioning. For details, see Versioning.

  • Action Transition

    This action archives objects by changing object storage class to Infrequent Access or Archive. When the specified date or time period arrives, the system changes the object storage class to Infrequent Access or Archive.

    • For buckets with versioning disabled, the Transition action changes the object storage class to Infrequent Access or Archive.
    • For buckets with versioning enabled and suspended, the Transition action changes the storage class of the current object version to Infrequent Access or Archive. This action has no impact on non-current object versions.
  • Action Expiration

    This action sets the time when objects expire. Objects become unavailable once they expire. Whether the expired objects will be permanently deleted depends on the versioning status of the bucket.

    The Expiration action will not delete uploaded parts of an incomplete multipart upload.

    • For buckets with versioning disabled, the Expiration action deletes objects permanently and the deleted objects cannot be restored.
    • For buckets with versioning enabled, this action applies only to current object versions, instead of non-current object versions. This action does not permanently delete current object versions. It retains the current version as a non-current version by adding a delete marker to it. This action will not be performed on current object versions that already have the delete markers. If the current object version is the only version of the object and has a delete marker, OBS will delete the current object version. Clearing a delete marker may take a while, because OBS needs to confirm that the delete marker is the only object version.

If you initiate a GET request on an object whose current version has the delete marker without specifying the version ID, OBS will identify the object as a deleted one and return error 404 Object Not Found. But you can specify the version ID in the GET request to recover the deleted object.

For example, you can set a rule to make the object named photo.gif expire 5 days after it is uploaded. If photo.gif is created at 10:30 UTC on January 1, 2016, the expiration rule will be executed at a time point after 00:00 UTC (five days after object creation) on January 7, 2016. The time will not be later than 23:59 UTC on January 7, 2016. For a bucket with versioning disabled, a deletion operation permanently deletes photo.gif. For a bucket with versioning enabled, after the expiration rule is executed, photo.gif (version 111111) is still stored in the bucket and can be accessed if needed, but the current version (version 4857693) of the object has a delete marker. The original object photo.gif turns to be a non-current version. For details about how a delete marker works, see Versioning.

For buckets with versioning suspended, OBS will create delete markers for expired objects whose version ID is null. Any existing null versions will be overwritten by new null versions, and data associated with this version cannot be restored.

Actions specific to buckets with versioning control enabled (or suspended)

The Transition and Expiration lifecycle actions can manage the lifecycle of current object versions. The NoncurrentVersionTransition and NonCurrentVersionExpiration actions can manage the lifecycle of noncurrent object versions.

The following lifecycle configuration actions can be performed only on buckets with versioning control enabled (or suspended). In a bucket with versioning control enabled, an object may have multiple versions, including a current version and zero or more non-current versions. You can use these actions to request OBS to perform specific operations on non-current object versions. These actions do not affect current object versions.

NoncurrentVersionTransition: Specifies the time period after which non-current versions will be transited from Standard to Infrequent Access or Archive.

NoncurrentVersionExpiration: Specifies the time period after which non-current object versions will be permanently deleted. A deleted object cannot be restored.

For example, if you want to enable a five-day period to correct any accidental deletion or overwriting, you can configure an expiration rule so that the object can be deleted 5 days after it has become a non-current version.

At 2016-01-01 10:30 (UTC time), you created an object named photo.gif whose version ID is 111111. At 2016-01-02 10:30 (UTC time), you accidentally deleted this object and OBS created a delete marker for this object using a new version ID, 4857693. In the next five days, you were allowed to restore the original object photo.gif whose version ID is 111111.

At 2016-01-08 00:00 (UTC time), the NoncurrentVersionExpiration action permanently deleted object photo.gif whose version ID is 111111 (after it became a non-current version for 5 days.)

How does OBS verify how long an object has become a non-current version?

In a bucket with versioning enabled, an object may have multiple versions, including a current version and zero or more non-current versions. Every time an object is uploaded, the existing current version is saved as a non-current version, while the uploaded version becomes the current version. To verify the days an object version has become a non-current version, OBS checks the creation time of the corresponding object of the current version. OBS uses the days that the object of the current version has been created as the days that the object of a non-current version has existed.

Restoring a non-current version using the lifecycle configuration

You can use either of the following methods to restore an object to a non-current version:

  1. Copy a non-current object version to the same bucket. The copied version will become the current version and all object versions are reserved.
  2. Delete the current object version permanently. After you delete the current version of an object, a non-current version of the object becomes the current version.

You are advised to use the first method to copy the non-current object version to the same bucket. Due to the consistency syntax of OBS, before the communication mode is changed, a current version that is permanently deleted may not disappear (OBS may be unaware of this deletion action). In addition, the expiration action for non-current versions, if you have configured, may delete the non-current object versions permanently, including those you want to restore. Therefore, the method of copying a non-current version is more secure.

Table 1 lists the relationship between the lifecycle configuration rule and versioning status of a bucket.

Table 1 Configuration actions and versioning status of buckets

Operation

Buckets with Versioning Disabled

Bucket with Versioning Enabled

Bucket with Versioning Suspended

Transition

(Performed on an object when the date arrives or time period specified by the lifecycle runs out.)

Objects can be changed to Infrequent Access or Archive.

If the current version does not have a delete marker and is the latest version, the current version can be changed to Infrequent Access or Archive.

If the current version does not have a delete marker and is not the latest version, the current version can be changed to Infrequent Access or Archive.

Expiration

(Performed on an object when the date arrives or time period specified by the lifecycle runs out.)

The Expiration action deletes objects, and deleted objects cannot be restored.

If the current version does not have a delete marker, a delete marker is created and is regarded as the current version. The existing current version becomes a non-current version.

For buckets with versioning suspended, OBS will create delete markers for expired objects whose version ID is null. Any existing null versions will be overwritten by new null versions, and data associated with this version cannot be restored.

NoncurrentVersionTransition

(Performed on an object after it becomes a non-current version for a specified number of days.)

NoncurrentVersionTransition action is invalid.

If the current version is not a delete marker and is not the latest version, the current version can be transited to Infrequent Access or Archive.

If the current version does not have a delete marker and is not the latest version, the current version can be changed to Infrequent Access or Archive.

NoncurrentVersionExpiration

(Performed on an object after it becomes a non-current version for a specified number of days.)

NoncurrentVersionExpiration action is invalid.

Non-current objects are deleted and cannot be restored once deleted.

If the current version does not have a delete marker and is not the latest version, the current version can be changed to Infrequent Access or Archive.

Date-based lifecycle rules

You can specify the execution dates for Transition and Expiration actions. The dates must conform to the ISO 8601 standards and the exact time is always 00:00 (UTC time). If you specify the time to a past date, all applicable objects will be executed immediately.

You cannot create date-based lifecycle rule on OBS Console.

A lifecycle action with a date specified is not a one-off action. Even if the date has passed, OBS will adopt this action as long as the lifecycle is enabled.

Assume you have specified a date for performing the Expiration action to delete all objects (without setting any filtering criteria). On the specified date, OBS makes all objects in the bucket expire. In addition, OBS continues to make all new objects created in the bucket expire. To terminate the Expiration action, you have to delete this action from your lifecycle configuration, disable the rule, or delete the rule from the lifecycle configuration.

Time period-based lifecycle rule

You can specify how many days after an object is created will the Transition or Expiration action will be performed on the object. After the number of days is specified, OBS starts to calculate the time from 00:00 (UTC time) on the next day. For example, you created an object at 2016-01-15 10:30 (UTC time) and you specified that objects would be changed 3 days after creation, the object would be transited at 2016-01-19 00:00 (UTC time).

OBS only records the last modification date for each object. On OBS Console, you can view the last modification time (LastModified) of an object on the object properties page. After an object is created, the date is the creation date. If the object is replaced, the date will also change.

When using the NoncurrentVersionTransition or NoncurrentVersionExpiration action, you can specify after how many days since an object changes to a non-current version (due to overwrite or deletion) will the action be performed on the object.

When you use the NoncurrentVersionTransition and NoncurrentVersionExpiration operations to specify the number of days, OBS adds the number of days specified in the rule to the time when the object version becomes a non-current version. Then the operation time is calculated starting from 00:00 (UTC time) of the next day. For example, the current version of an object in a bucket is created at 10:30 UTC on January 1, 2016. If the object version becomes a non-current version at 10:30 UTC on January 15, 2016 and you specify three days in the conversion rule, then the date for changing object storage class is calculated as 00:00 UTC on January 19, 2016.

When configuring the lifecycle rules, within a rule and for rules whose prefixes have inclusion relationship, Date or Days of Transition and Expiration must be consistent.

How to Use This Function

You can use OBS Console, APIs, or SDKs to configure lifecycle rules.

Tool

Reference

OBS Console

Configuring a Lifecycle Rule

SDKs

OBS supports software development kits (SDKs) in multiple languages. For details, see the corresponding development guide on the SDK Overview page.

APIs

Configuring Bucket Lifecycle Rules

Obtaining Bucket Lifecycle Configuration

Deleting Lifecycle Rules