Help Center/ Object Storage Service/ FAQs/ Buckets and Objects/ How Do I Batch Delete a Large Number of Objects from a Bucket or Empty a Bucket?
Updated on 2024-08-09 GMT+08:00

How Do I Batch Delete a Large Number of Objects from a Bucket or Empty a Bucket?

You can batch delete a large number of objects from a bucket or empty a bucket by referring to the procedure below:

Method: Using Lifecycle Rules

You can use the OBS lifecycle management to periodically empty all objects in a bucket at a time or batch delete objects based on a specified prefix.

  1. Log in to OBS Console.
  2. In the navigation pane of OBS Console, choose Object Storage.
  3. In the bucket list, click the bucket you want to operate to go to the Objects page.
  4. In the navigation pane, choose Overview.
  5. In the Basic Configurations area, click Lifecycle Rules. The Lifecycle Rules page is displayed.
  6. Click Create. A dialog box shown in Figure 1 is displayed.

    Figure 1 Creating a lifecycle rule

  7. Configure a lifecycle rule for emptying a bucket or batch deleting objects with a specified prefix.

    Table 1 Lifecycle rule parameters

    Category

    Parameter

    Description

    Basic information

    Status

    Select Enable.

    Rule Name

    User-defined. It identifies a lifecycle rule.

    Prefix

    Optional.

    • If this parameter is configured, objects with the specified prefix will be deleted in a batch.
    • If this parameter is not configured, all objects in the bucket will be deleted.

    Current version/Historical version

    Transition to Infrequent Access After (Days)

    Do not select this parameter.

    Transition to Archive After (Days)

    Do not select this parameter.

    Delete Objects After (Days)

    Select this parameter and specify a number. It indicates the number of days after the last update when objects are automatically deleted. The minimum value is 1 day. If any of the transition operations is configured, this parameter must be set to a number larger than that specified for any of the transition operations.

    NOTE:

    If versioning is not enabled for the current bucket, specified objects will be automatically deleted after they expire and cannot be recovered.

    Delete Fragments After (Days)

    This parameter is only available for current version. It indicates the number of days after creation when fragments in the bucket are automatically deleted. The minimum value is 1.

    • Current version and Historical version are two concepts for Versioning. If versioning is enabled for a bucket, uploading objects with the same name to the bucket creates different object versions. The object uploaded lastly is called Current Version, and the object uploaded previously is called Historical Version.
    • Either the Current Version or Historical Version must be configured, or you can configure both of them. If you want to empty the bucket, configure both of them.
    • There may be a delay for deleting objects after the objects expire. The delay generally does not exceed 48 hours. If you change the configurations of an existing lifecycle rule, the rule will take effect again.

  8. Click OK to complete the configuration.