Convert appendable objects to Cold Archive

更新时间:
复制 MD 格式

Lifecycle rules in Object Storage Service (OSS) cannot directly transition appendable objects to the Cold Archive or Deep Cold Archive storage class because they are writable. If you no longer need to append data to an appendable object, you can convert it to a normal object with the SealAppendObject operation. After the conversion, lifecycle rules can automatically transition the object to the Cold Archive or Deep Cold Archive storage class to reduce your long-term storage costs.

Important

To use the SealAppendObject operation, submit a ticket for approval.

This topic provides an example of how to convert appendable objects to the Cold Archive storage class. In this example, the objects are in a bucket named examplebucket, have the prefix appendobjects/, and were last modified more than 30 days ago.

Step 1: List appendable objects

Filter and list all matching appendable objects to identify the objects to seal.

Important

If versioning is not enabled for a bucket, each append operation updates the last modified time (Last-Modified) of an appendable object. If versioning is enabled or suspended for the bucket, the last modified time remains the same as its initial upload time and is not updated by subsequent appends. Therefore, if versioning is enabled or suspended for the bucket, this operation lists all appendable objects that were initially uploaded more than 30 days ago.

Ossutil

Run the following command to list all matching appendable objects. This example lists appendable objects that meet the following criteria: the last modified time is more than 30 days ago, the storage class is not Cold Archive or Deep Cold Archive, and the object is unsealed. Note the order of the filter conditions in the command.

ossutil ls oss://examplebucket/appendobjects/ -r -q --short-format  --min-age=30d  --metadata-exclude="x-oss-storage-class=*ColdArchive" --metadata-exclude="x-oss-sealed-time=*" --metadata-include="x-oss-object-type=Appendable"

Sample response:

oss://examplebucket/appendobjects/unsealed_object1.txt
oss://examplebucket/appendobjects/unsealed_object2.txt
oss://examplebucket/appendobjects/unsealed_object3.txt

API

Call the GetBucket (ListObjects) or ListObjectsV2 (GetBucketV2) API operation to iterate through all objects that have the specified prefix. Filter the results to find the target objects based on the following conditions:

  • The value of the <Type> field is Appendable.

  • The value of the <StorageClass> field is not ColdArchive or DeepColdArchive.

  • The value of the <LastModified> field indicates a time more than 30 days ago.

  • The response does not contain the <SealedTime> field.

Step 2: Seal appendable objects

Perform the SealAppendObject operation to convert the appendable objects to normal objects so that lifecycle rules can transition them.

Ossutil

  1. Get the object size: Run the stat command to get the Content-Length of the object. Use this value as the position parameter for the SealAppendObject operation.

    ossutil stat oss://examplebucket/appendobjects/unsealed_object1.txt
  2. Perform the SealAppendObject operation: Use the invoke-operation command to call the SealAppendObject API. Pass the Content-Length from the previous step, such as 65536, as the value for the position parameter.

    ossutil api invoke-operation --op-name seal --method POST --bucket examplebucket --key appendobjects/unsealed_object1.txt --parameters seal --parameters position=65536

API

  1. Get the object size: Get the <Size> value of the target object from the response of the GetBucket (ListObjects) or ListObjectsV2 (GetBucketV2) API operation.

  2. Perform the SealAppendObject operation: For each target object, call the SealAppendObject API operation. Use the <Size> value from the previous step as the value for the position parameter in the request. This converts the object to a non-appendable state.

Step 3: Configure a lifecycle rule

Configure a lifecycle rule to automatically transition objects to the Cold Archive or Deep Cold Archive storage class after a specified period.

Note: This rule applies to all normal objects, including objects uploaded with PutObject or multipart upload, and appendable objects that have been sealed. Ensure that the prefix in the rule is specific enough to avoid unintended object transitions.

Console

  1. Log on to the OSS console.

  2. Click Buckets, and then click examplebucket.

  3. In the left-side navigation pane, choose Data Management > Lifecycle.

  4. Click Create Rule. Configure the lifecycle rule as described in the following table and keep the default values for the other parameters.

    Area

    Parameter

    Configuration

    Basic Settings

    Status

    Select Enabled.

    Applied To

    Select Object Prefix.

    Prefix

    Enter appendobjects/.

    Policy for Current Versions

    Object Lifecycle

    Select Validity Period (Days).

    Lifecycle-based Rules

    Set a rule to transition objects to Cold Archive 30 days after their Modified Time.

  5. Click OK.

Ossutil

  1. Create a file named lifecycle.xml and add the following content. This rule transitions objects that have the appendobjects/ prefix and last modified more than 30 days ago to the ColdArchive storage class.

    <LifecycleConfiguration>
      <Rule>
        <ID>rule1</ID>
        <Prefix>appendobjects/</Prefix>
        <Status>Enabled</Status>
        <Transition>
          <Days>30</Days>
          <StorageClass>ColdArchive</StorageClass>
        </Transition>
      </Rule>
    </LifecycleConfiguration>
  2. Run the following command to apply the lifecycle rule to the examplebucket bucket.

    ossutil api put-bucket-lifecycle --bucket examplebucket --lifecycle-configuration file://lifecycle.xml

API

Call the PutBucketLifecycle API operation and include the XML content in the request body to apply the rule to the target bucket examplebucket.

PUT /?lifecycle HTTP/1.1
Host: oss-examplebucket.oss.aliyuncs.com
Content-Length: 336
Date: Mon, 6 May 2025 15:23:20 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250506/cn-hangzhou/oss/aliyun_v4_request,AdditionalHeaders=content-length,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
<?xml version="1.0" encoding="UTF-8"?>
<LifecycleConfiguration>
  <Rule>
    <ID>rule1</ID>
    <Prefix>appendobjects/</Prefix>
    <Status>Enabled</Status>
    <Transition>
      <Days>30</Days>
      <StorageClass>ColdArchive</StorageClass>
    </Transition>
  </Rule>
</LifecycleConfiguration>

Verify the results

After you configure the lifecycle rule, it typically takes effect and runs for the first time early the next morning.

After the rule takes effect, you can check the storage class of the target objects to verify that they have transitioned to the Cold Archive storage class. You can check the storage class in the OSS console or by running the ossutil stat command.