You can use the bucket inventory feature to export information about specific objects in a bucket, such as the number, sizes, storage classes, and encryption state of the objects. To list a large number of objects, we recommend that you use the bucket inventory feature instead of the GetBucket (ListObjects) operation. This topic describes how to run the inventory command to add, query, list, or delete bucket inventories.
Sample command lines in this topic are based on the 64-bit Linux system. For other systems, replace ./ossutil64 in the commands with the corresponding binary name. For more information, see ossutil.
For more information about the bucket inventory feature, see Bucket inventory.
Add inventories
You can perform the following steps to add an inventory for a bucket:
Create a Resource Access Management (RAM) role and authorize the role to read all objects in the source bucket and write objects in the destination bucket in which inventory lists are generated. For more information about how to create a RAM role, see Create a RAM role for a trusted Alibaba Cloud service.
Create a local file and configure inventories in the XML format in the file.
Use ossutil to read the inventories from the local file and add the inventories to the specified bucket.
Syntax
./ossutil64 inventory --method put oss://bucketname local_xml_file
The following table describes the parameters.
Parameter
Description
bucketname
The name of the bucket for which you want to add inventories.
local_xml_file
The name of the local file in which the inventory is configured. Example:
localfile.xml
.Examples
Create a file named localfile.xml on the local computer and write different inventories to the file.
The following example shows an inventory named inventorytest. Based on this inventory, Object Storage Service (OSS) exports the information about all objects in a bucket named destbucket, including the storage classes, last update date, and multipart upload status of the objects. Exported inventory lists are encrypted by using the AES256 algorithm.
<?xml version="1.0" encoding="UTF-8"?> <InventoryConfiguration> <Id>inventorytest</Id> <IsEnabled>true</IsEnabled> <Filter> <Prefix>dir/</Prefix> </Filter> <Destination> <OSSBucketDestination> <Format>CSV</Format> <AccountId>1746495857602745</AccountId> <RoleArn>acs:ram::174649585760****:role/AliyunOSSRole</RoleArn> <Bucket>acs:oss:::destbucket</Bucket> <Encryption> <SSE-OSS></SSE-OSS> </Encryption> </OSSBucketDestination> </Destination> <Schedule> <Frequency>Weekly</Frequency> </Schedule> <IncludedObjectVersions>All</IncludedObjectVersions> <OptionalFields> <Field>LastModifiedDate</Field> <Field>StorageClass</Field> <Field>IsMultipartUploaded</Field> <Field>ETag</Field> <Field>EncryptionStatus</Field> <Field>Size</Field> </OptionalFields> </InventoryConfiguration>
ImportantYou can add multiple inventories for a bucket. The inventories are uniquely identified by their IDs. If the ID of the inventory that you want to add is the same as that of an existing inventory, HTTP status code 409 is returned.
Add the inventories for a bucket named examplebucket.
./ossutil64 inventory --method put oss://examplebucket localfile.xml
If the inventories are added for examplebucket, a similar output is displayed.
0.299514(s) elapsed
Query a specified inventory configured for a bucket
Syntax
./ossutil64 inventory --method get oss://bucketname inventory_id [--local_xml_file ]
The following table describes the parameters.
Parameter
Description
bucketname
The name of the bucket whose inventories you want to query.
inventory_id
The name of the inventory that you want to query.
local_xml_file
The name of the local file used to store the obtained inventory. Example:
localfile.txt
. If this parameter is not specified, obtained inventories are displayed without being stored in a local file.Examples
./ossutil64 inventory --method get oss://examplebucket inventorytest localfile.txt
If an inventory named inventorytest is configured for the bucket named examplebucket, and the inventory is written to a local file named localfile.txt, a similar output is displayed.
0.212407(s) elapsed
Query all inventory rules configured for a bucket
Syntax
./ossutil64 inventory --method list oss://bucketname [--local_xml_file ] [--marker <value>]
The following table describes the parameters.
Parameter
Description
bucketname
The name of the bucket whose inventories you want to query.
local_xml_file
The name of the local XML file used to store the obtained inventories. If this parameter is not specified, obtained inventories are displayed without being stored in a local file.
marker
The filtering conditions for inventories. Inventory lists are generated for only objects whose names contain the specified prefix. If this parameter is not specified, inventory lists are generated for all objects in the bucket.
Examples
./ossutil64 inventory --method list oss://examplebucket localfile.txt dest
If all inventories that are configured for a bucket named examplebucket and apply to objects whose names contain the dest prefix are obtained and written to a local file named localfile.txt, a similar output is displayed.
0.216897(s) elapsed
Delete a specified inventory for a bucket
Syntax
./ossutil64 inventory --method delete oss://bucketname inventory_id
The following table describes the parameters.
Parameter
Description
bucketname
The name of the bucket for which you want to delete the inventory.
inventory_id
The name of the inventory that you want to delete.
Examples
./ossutil64 inventory --method delete oss://examplebucket inventorytest
If an inventory named inventorytest is deleted for a bucket named examplebucket, a similar output is displayed.
0.212407(s) elapsed
Common options
If you use ossutil to switch to a bucket that is located in another region, add the -e option to the command to specify the endpoint of the region in which the specified bucket is located. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, you can add the -i option to the command to specify the AccessKey ID of the specified account, and add the -k option to the command to specify the AccessKey secret of the specified account.
For example, you can run the following command to configure inventories for a bucket named examplebucket that is located in the China (Hangzhou) region and owned by another Alibaba cloud account:
./ossutil64 inventory --method put oss://examplebucket local_xml_file -e oss-cn-hangzhou.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA**** -k 67DLVBkH7EamOjy2W5RVAHUY9H****
For more information about other common options that you can use for the sync command, see Common options.