The lifecycle command is used to add, modify, query, or delete lifecycle configurations.

Note
  • The commands described in this topic apply to Linux. To use the commands in other systems, replace ./ossutil in the command with the actual executable program name. For example, you can use the help command in 32-bit Windows systems by running ossutil32.exe help.
  • For more information about lifecycle rules, see Lifecycle rules.

Command syntax

  • Add or modify lifecycle configurations
    ./ossutil lifecycle --method put oss://bucket local_xml_file [options]
    ossutil reads the configurations of lifecycle rules in local_xml_file, and adds the rules obtained from the configuration file for the bucket. If the rule ID exists in the configuration file, ossutil overwrites the configurations of the existing rule ID.
    A lifecycle configuration file is an XML file that describes the rules on handling expired objects, such as whether to delete the object or to convert the storage class of expired objects. You can configure the rules based on your needs. The following code provides an example of a complete lifecycle configuration:
    <? xml version="1.0" encoding="UTF-8"? >
    <LifecycleConfiguration>
      <Rule>
        <ID>RuleID</ID>
        <Prefix>Prefix</Prefix>
        <Status>Status</Status>
        <Expiration>
          <Days>Days</Days>
        </Expiration>
        <Transition>
          <Days>Days</Days>
          <StorageClass>StorageClass</StorageClass>
        </Transition>
        <AbortMultipartUpload>
          <Days>Days</Days>
        </AbortMultipartUpload>
      </Rule>
    </LifecycleConfiguration>
    For more information about lifecycle configurations, see Configuration elements.
  • Query lifecycle configurations
    ossutil lifecycle --method get oss://bucket [local_file]

    The local_file parameter specifies the name of the configuration file. If this parameter is specified, ossutil saves the obtained lifecycle configurations as a local file. If this parameter is not specified, ossutil displays the obtained lifecycle configurations.

  • Delete lifecycle configurations
    ./ossuitl lifecycle --method delete oss://bucket

Examples

  • Add a lifecycle rule that changes the storage class of objects uploaded for 10 days and prefixed by test/ to IA
    ./ossutil lifecycle --method put oss://bucket1  /file/lifecycle.xml
    The content of the lifecycle.xml configuration file is as follows:
    <? xml version="1.0" encoding="UTF-8"? >
    <LifecycleConfiguration>
      <Rule>
        <ID>1</ID>
        <Prefix>test/</Prefix>
        <Status>Enabled</Status>
        <Transition>
          <Days>10</Days>
          <StorageClass>IA</StorageClass>
        </Transition>
     </Rule>
    </LifecycleConfiguration>
  • Add a lifecycle rule that deletes objects modified before January 1, 2019 and prefixed by test/
    ./ossutil lifecycle --method put oss://bucket1  /file/lifecycle.xml
    The content of the lifecycle.xml configuration file is as follows:
    <? xml version="1.0" encoding="UTF-8"? >
    <LifecycleConfiguration>
      <Rule>
        <ID>2</ID>
        <Prefix>test/</Prefix>
        <Status>Enabled</Status>
        <Expiration>
          <CreatedBeforeDate>2019-01-01T00:00:00.000Z</CreatedBeforeDate>
        </Expiration>
     </Rule>
    </LifecycleConfiguration>
  • Query lifecycle configurations
    ./ossutil lifecycle --method get oss://bucket1  /file/lifecycle.xml
  • Delete lifecycle configurations
    ./ossutil lifecycle --method delete oss://bucket1  

Common options

The following table describes the options you can add to the lifecycle command.
Option Description
--method Specifies the HTTP request method. Valid values:
  • put: adds or modifies lifecycle configurations.
  • get: queries lifecycle configurations.
  • delete: deletes lifecycle configurations.
--loglevel Specifies the log level. The default value is null, which indicates that no log files are generated. Valid values:
  • info: generates prompt logs.
  • debug: generates detailed logs that contain corresponding HTTP request and response information.
--proxy-host Specifies the URL of the proxy server. HTTP, HTTPS, and SOCKS5 proxies are supported. Examples: http://120.79. **.**:3128 and socks5://120.79. **. **:1080.
--proxy-user Specifies the username of the proxy server. The default value is null.
--proxy-pwd Specifies the password of the proxy server. The default value is null.
Note For more information about common options, see View all supported options.