You can create lifecycle rules for a bucket based on the last modified time and last access time of objects in the bucket. This way, Object Storage Service (OSS) can regularly convert the storage class of the objects or delete expired objects and parts to reduce your storage costs.

Background information

A lifecycle rule can contain policies based on both the last modified time and the last access time of objects. When you configure lifecycle rules, take note of the following limits:
  • Number of rules

    You can configure up to 100 lifecycle rules in the OSS console. To configure more than 100 lifecycle rules, use OSS SDKs or the command-line tool ossutil.

  • Region

    You can configure lifecycle rules based on the last access time only for buckets in the China (Qingdao), China (Hohhot), Germany (Frankfurt), and Australia (Sydney) regions.

  • Effective time

    After a lifecycle rule is configured, the rule is loaded within 24 hours and takes effect within 24 hours after the rule is loaded. Check the configurations of a lifecycle rule before you save the rule.

For more information about lifecycle rules that are configured based on the last modified time and the last access time of objects, see Overview.

Procedure

  1. Log on to the OSS console.
  2. In the left-side navigation pane, click Buckets. On the Buckets page, click the name of the desired bucket.
  3. In the left-side navigation pane, choose Basic Settings > Lifecycle. In the Lifecycle section, click Configure.
  4. If you want to create lifecycle rules based on the last access time of objects, turn on Enable access tracking on the Lifecycle page.
  5. On the page that appears, click Create Rule. In the Create Rule panel, configure the parameters. The following table describes the parameters.
    • Parameters for unversioned buckets
      Section Parameter Description
      Basic Settings Status

      Specify the status of the lifecycle rule. Valid values: Enabled and Disabled.

      Applied To

      Specify the objects to which the lifecycle rule applies. Valid values: Files with Specified Prefix and Whole Bucket.

      Allow Overlapped Prefixes

      If you select Allow Overlapped Prefixes, you can configure lifecycle rules with the same or overlapping prefixes without specifying tags.

      Notice
      • If you want OSS to automatically detect whether rules with the same or overlapping prefixes are configured, do not select Allow Overlapped Prefixes.
      • If you want to use this parameter, contact technical support.
      Prefix
      Specify the prefix in the names of objects to which the lifecycle rule takes effect.
      • If you set the prefix to img, all objects whose names start with img, such as imgtest.png and img/example.jpg, match the lifecycle rule.
      • If you set the prefix to img/, all objects whose names start with img/, such as img/example.jpg and img/test.jpg, match the lifecycle rule.
      Tagging

      Specify tags. The rule applies only to objects that have the specified tags. For example, if you select Files with Specified Prefix and set Prefix to img, Key to a, and Value to 1, the rule applies to all objects that have the img prefix in their names and have the tag a=1. For more information about object tagging, see Object tagging.

      NOT

      The NOT parameter is used to specify that the lifecycle rule does not apply to objects that have the specified prefix and tags.

      Notice
      • If you enable NOT, each lifecycle rule must contain at least one of the prefix and tags of an object.
      • The key of the tag specified by the NOT syntax cannot be the same as the key specified by the Tagging parameter.
      • If you enable NOT, lifecycle rules that apply to parts cannot be configured.
      • If you want to use this parameter, contact technical support.
      Policy for Objects File Lifecycle

      Configure rules for objects to specify when the objects expire. Valid values: Validity Period (Days), Expiration Date, and Disabled. If you select Disabled, the configurations of File Lifecycle do not take effect.

      Lifecycle-based Rules

      Configure the policy to convert the storage class of objects or delete expired objects.

      Example 1: If you select Access Time, set Validity Period (Days) to 30, and specify that the storage class of the objects is converted to IA (Not Converted After Access) after the validity period ends. In this case, the storage class of objects that were last accessed on September 1, 2021 is converted to Infrequent Access (IA) on October 1, 2021.

      Note If you configure a lifecycle rule based on the last access time, you can specify that the rule takes effect only to objects that are larger than 64 KB in size or to all objects in the bucket.

      Example 2: If you select Modified Time, set Expiration Date to September 24, 2021, and specify that objects that are last modified before this date are deleted. In this case, objects that are last modified before September 24, 2021 are automatically deleted. The deleted objects cannot be recovered.

      Policy for Parts Part Lifecycle

      Specify the operations that you want to perform on expired parts. If you select Tagging, this parameter is unavailable. You can select Validity Period (Days), Expiration Date, or Disabled. If you select Disabled, the configurations of Part Lifecycle do not take effect.

      Notice Each lifecycle rule must contain at least one of object expiration policies and part expiration policies.
      Rules for Parts

      Specify when parts expire based on the value of Part Lifecycle. Expired parts are automatically deleted and cannot be recovered.

    • Parameters for versioned buckets

      Configure the parameters in the Basic Settings and Policy for Parts sections in the same way as the parameters configured for unversioned buckets. The following table describes only the parameters that are different from the parameters that you configure for unversioned buckets.

      Section Parameter Description
      Policy for Current Versions Clean Up Delete Marker

      If you enable versioning for the bucket, you can configure the Clean Up Delete Marker parameter. Other parameters are the same as those you can configure for unversioned buckets.

      If you select Clean Up Delete Marker, and an object has only one version which is a delete marker, OSS considers the delete marker expired and removes the delete marker. If an object has multiple versions and the current version of the object is a delete marker, OSS retains the delete marker. For more information about delete makers, see Delete marker.

      Policy for Previous Versions File Lifecycle

      Specify when previous versions expire. Valid values: Validity Period (Days) and Disabled. If you select Disabled, File Lifecycle does not take effect.

      Lifecycle-based Rules

      Specify the number of days within which objects can be retained after they become previous versions. After they expire, the specified operations are performed on the previous versions the next day. For example, if you set Validity Period (Days) to 30, objects that become previous versions on September 1, 2021 are converted to the specified storage class or deleted on October 1, 2021.

      Notice You can determine when an object becomes a previous version based on the time when the next version of the object is last modified.
  6. Click OK.
    After a lifecycle rule is saved, you can view the rule in the lifecycle rule list.