This topic describes how to set lifecycle rules for an Object Storage Service (OSS) bucket and configure automated file archiving to automatically archive files on a file gateway.

Prerequisites

  • You have created a Standard or Infrequent Access (IA) OSS bucket. For more information, see Create buckets.
    Note Cloud Storage Gateway (CSG) supports Standard, IA, and Archive OSS buckets.
  • You have created a share.
    Note
    • CSG only automatically archives files in NFS shares on a file gateway. When you create the share, set Protocol to NFS.
    • When you create the share, set Support Archive to Yes.
    • For more information about how to create shares on file gateways deployed on Alibaba Cloud, see Create a share.
    • For more information about how to create shares on on-premises file gateways, see Manage NFS shares.

Background information

CSG V1.0.44 and later versions can automatically archive files on file gateways to OSS buckets.

For files in a Standard or IA OSS bucket, you can directly use the file gateway to automatically archive and unarchive the files, and query the archiving information. You do not need to use the OSS console to manage the lifecycle of a file.
Note To automate file archiving, you must set lifecycle rules for the OSS bucket in the OSS console first. You do not need to set lifecycle rules if you only need to unarchive files or query the archiving information.

Step 1: Set lifecycle rules for the OSS bucket

You can create lifecycle rules to change the storage class of one or more objects in an OSS bucket.

  1. Log on to the OSS console.
  2. In the left-side navigation pane, click the name of the target bucket. You are redirected to the Overview tab.
  3. Click the Basic Settings tab. In the Lifecycle section, click Configure.
  4. On the Lifecycle page, click Create Rule.
  5. On the Create Rule page that appears, set the following parameters.
    Parameter Description
    Status Select Enabled.
    Applied To Select Whole Bucket to apply the policy to all objects in an OSS bucket.
    Note If you select Whole Bucket, you can create only one lifecycle rule for the bucket.
    Tagging Select the Tagging check box and add tags to apply the rule to objects with the specified tags.
    • Set Key to AutoArchive.
    • Set Value to enabled.
    Clear Policy Set the file expiration rule. You can select Validity Period (Days) or Expiration Date.
    Transit to Archive Storage Class Select Transit to Archive Storage Class and then set the validity period or expiration date. In this example, the validity period is set to one day.
    • Validity Period (Days): Specify the validity period of files, which starts from the last updated date of the files. The files are archived when the validity period ends. For example, if you set the validity period to one day and the last updated date of the files is October 1, 2019, the system will scan for expired files and archive them on October 2, 2019.
      Note For more information about the pricing of archive files, see Manage object lifecycle.
    • Expiration Date: Specify a file expiration date. Files whose last updated dates are earlier than the specified expiration date are considered expired files and archived. For example, if you set the expiration date to October 1, 2019, the system will scan for files whose last updated dates are earlier than October 1, 2019 and archive these files.
  6. Click OK.
    Notice
    • Lifecycle rules are applied immediately after they are created. Make sure that the rules are correctly configured before you save them.
    • For more information about lifecycle rules, see Manage object lifecycle.

Step 2: Complete the archive management configuration

  1. Log on to your host that runs the Linux operating system.
  2. Download the gateway archive management tool: sgw_archive_util.
  3. Run the following command to grant the permission to run the archive management tool:
    sudo chmod a+x sgw_archive_util
  4. Run the following command to enable the archive management tool to automatically archive a file:
    sgw_archive_util –a /path/file

    /path/file represents the absolute path of the file. Replace it with the actual file path.

  5. Run the following command to verify the archiving result:
    ossutil object-tagging --method get oss://file-wanqp/0816/0.txt

    oss://file-wanqp/0816/0.txt represents the path of the archive file in the OSS bucket. Replace it with the actual file path.

    In step 1, the validity period is set to one day. The file will be archived one day after its last updated date.

    If the following information appears, it indicates that the file is archived.

    归档管理01

Other operations

  • You can run the following command to use the archive management tool to automatically unarchive an archive file:
    sgw_archive_util -r /path/file

    /path/file represents the absolute path of the file. Replace it with the actual file path.

  • You can run the following command to use the archive management tool to query the archiving information for a file:
    sgw_archive_util -q /path/file

    /path/file represents the absolute path of the file. Replace it with the actual file path.