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

Prerequisites

  • A Standard or Infrequent Access (IA) OSS bucket is created. For more information, see Create buckets.
    Note Cloud Storage Gateway (CSG) supports Standard, IA, and Archive OSS buckets.
  • A share is created.
    Note
    • CSG automatically archives files only in NFS shares on a file gateway. When you create the share, set the Protocol parameter to NFS.
    • When you create the share, set the User Mapping parameter to none.
    • When you create the share, set the Support Archive parameter to Yes.
    • For more information about how to create shares on file gateways that are 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.

You can directly use the file gateway to automatically archive and restore files that are in a Standard or IA OSS bucket, and query the archive 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 OSS 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, set the parameters. The following table describes the parameters.
    Parameter Description
    Status Select Enabled.
    Action 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.
    Label Select the Tagging check box and add tags to apply the rule to objects that have the specified tags.
    • Set Key to AutoArchive.
    • Set Value to enabled.
    File Lifecycle Configure 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 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 the files. The files are archived when the validity period ends. For example, if you set the validity period to one day and the date that the files are most recently updated is October 1, 2019, the system scans for expired files and archives expired files on October 2, 2019.
      Note For more information about the pricing of archive files, see Lifecycle rules.
    • Expiration Date: Specify a file expiration date. If the date that a file is most recently updated is earlier than the specified expiration date, the file is considered expired and the system archives the file. For example, if you set the expiration date to October 1, 2019, the system scans for files that are most recently updated before October 1, 2019 and then archives these files.
  6. Click OK.
    Notice
    • Lifecycle rules immediately take effect after they are created. Make sure that the rules are configured based on your business requirements before you save them.
    • For more information about lifecycle rules, see Lifecycle rules.

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 files:
    sgw_archive_util –a /path/file

    /path/file indicates 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 indicates the path of the archive file in the OSS bucket. Replace it with the actual file path.

    In Step 1: Set lifecycle rules for the OSS bucket, the validity period is set to one day. The file is archived one day after the date that the file is most recently updated.

    If the following information appears, the file is archived.

    Verify the result.

Other operations

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

    /path/file indicates 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 archive information of a file:
    sgw_archive_util -q /path/file

    /path/file indicates the absolute path of the file. Replace it with an actual file path.