This topic describes how to use the Alibaba Cloud quota_tool tool to manage Apsara File Storage NAS (NAS) quotas on ECS instances that have NAS file systems mounted. You can configure, view, and cancel quotas on these ECS instances.

Prerequisites

An NFS file system of the NAS Capacity or NAS Performance type is mounted on an ECS instance. For more information, see Mount an NFS file system.

Background information

NAS allows you to view and manage directory-level quotas with ease. Directory-level quotas specify the maximum number of files in each folder and the maximum storage space that is allowed for these files.

From the perspective of the application scope, quotas are sorted into quotas for all users and quotas for a single user or group. Quotas for all users specify the maximum storage space allowed for files that all users can create in a directory. Quotas for a single user or group specify the maximum storage space allowed for files that a user or group can create in a directory.

From the perspective of limits, quotas are sorted into quotas for statistics and quotas for restriction. Quotas for statistics only collect the usage of the storage space. It provides an easy method to retrieve and view statistical data. Quotas for restriction specify the maximum capacity of storage space for files that you can create in a directory. If the limit is exceeded, you may fail to create a file or subdirectory, append data to a file, or perform other operations.
Notice
  • You can only configure quotas for statistics.
  • You can only configure quotas for file systems that reside in China (Zhangjiakou-Beijing Winter Olympics), China (Hohhot), Australia (Sydney), Malaysia (Kuala Lumpur), and US (Silicon Valley).
  • NAS performs asynchronous calculation for quotas at the backend. When you use the quota_tool tool to retrieve statistical data about quotas, the process requires a period of time to complete. In most cases, the time period is about 5 to 15 minutes.

Configure quotas

The following uses the /mnt directory as an example.

  1. Log on to the Elastic Compute Service (ECS) instance with the root account.
    You can use the quota_tool tool on an ECS instance that has a NAS file system mounted. You must run the tool with the root permissions. The following describes how to use the quota_tool tool on an ECS instance.
  2. Use the following command to download the quota_tool tool.
    wget https://nasimport.oss-cn-shanghai.aliyuncs.com/quota_tool_v1.0 -O quota_tool
  3. Use the following command to grant the execute permission to the quota_tool tool.
    sudo chmod a+x quota_tool
  4. Configure quotas.
    Note For each file system, you can only configure quotas for a maximum of 10 directories.

    The syntax of the command that you use to configure quotas is sudo ./quota_tool set --dir [DIR] [OPTION].

    Parameter Description
    --dir [DIR] Specifies the directory for which you want to configure quotas. For example, --dir /mnt/data/.
    OPTION Specifies the required options for the OPTION parameter.
    Note When you specify options for the parameter, you must follow these rules. the --accounting option is required, one of the following options is required: --alluser, --uid, and --gid, .
    • --accounting: specifies a quota for statistics.
    • --alluser: specifies a directory-level quota for all users.
    • --uid: introduces the UID of a user. For example, --uid 505 only collects a quota for a user whose UID is 505.
    • --gid: introduces the GID of a group. For example, --gid 1000 only collects a quota for a group whose GID is 1000.

    The following examples describe how to configure quotas.

    • Use the following command to configure a quota for statistics for the /mnt/data/ directory to retrieve the total number of files that reside in a directory.
      sudo ./quota_tool set --dir /mnt/data/ --accounting --alluser
    • Use the following command to configure a quota for statistics for the /mnt/data/ directory to retrieve the total number of files that are created by a user whose UID is 505.
      sudo ./quota_tool set --dir /mnt/data/ --accounting --uid 505

Retrieve quotas

After you configure a quota for a NAS directory, you can retrieve statistical data about the quota for the directory.

  1. Log on to the ECS instance with the root account.
  2. Use the following command to retrieve quotas.
    sudo ./quota_tool get --dir /mnt/data/

    Use the sudo ./quota_tool get --dir /mnt/data/ --all command to retrieve all quotas you specify for the /mnt/data/ directory.

    Note
    • During the process of retrieving a quota for the first time, a state called Initializing appears. After the initialization process is complete, you can receive the quota and a result showing success appears. The duration of the initialization process is based on the number of files and subdirectories that are included in a directory.
    • Before the expected FileCountReal and SizeReal are displayed, a delay of 5 to 10 minutes may occur when you perform daily retrieval of quotas after the initialization process is complete. This occurs due to the asynchronous calculation for quotas at the backend.
    Retrieve quotas

    The following table lists parameters that are included in a response in the JSON format.

    Parameter Description
    Path Indicates a directory for which you retrieve a quota.
    Report Includes all information about a quota that is specified for a directory, for example, UID and GID.
    ReportStatus The state for the retrieval of a quota.
    FileCountLimit Indicates the limit for the number of files. A value of Empty indicates no limit.
    FileCountReal Indicates the total number of files including subdirectories, files, and special files that reside in a directory.
    QuotaType Accounting indicates a quota for statistics .
    Uid Indicates the UID of a user. A value of All indicates all users.
    Gid Indicates the GID of a group. The value of All indicates all groups.
    SizeLimit Indicates the maximum capacity of files that reside in a directory. The value of Empty indicates no limit.
    SizeReal Indicates the total capacity of files that reside in a directory.

Cancel quotas

After you configure a quota, you can also cancel the quota.

  1. Log on to the Elastic Compute Service (ECS) instance with the root account.
  2. Cancel quotas.

    The syntax of the command that you can use to cancel quotas is sudo ./quota_tool cancel --dir [DIR] [OPTION].

    Parameter Description
    --dir [DIR] Specifies the directory for which you want to cancel quotas, for example, -dir /mnt/data/.
    OPTION Configure the required option for the OPTION parameter.
    Note When you configure the OPTION parameter, one of the following options is required: --alluser, --uid, and --gid.
    • --alluser: cancels a quota for all users.
    • --uid: introduces the UID of a user. For example, --uid 505 cancels a quota for a user whose UID is 505.
    • --gid: introduces the GID of a group. For example, --gid 505 cancels a quota for a group whose GID is 505.

    The following examples describes how to cancel quotas.

    • You configure a quota for the /mnt/data/ directory. Use the following command to cancel the quota for a user whose UID is 100.
      sudo ./quota_tool cancel --dir /mnt/data/ --uid 100
    • You configure a quota for the /mnt/data/ directory. Use the following command to cancel the quota for all users.
      sudo ./quota_tool cancel --dir /mnt/data/ --alluser