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.
- In the navigation pane of OBS Console, choose Object Storage.
- In the bucket list, click the bucket you want to operate to go to the Objects page.
- In the navigation pane, choose Basic Configurations > Lifecycle Rules.
- Click Create. A dialog box shown in Figure 1 is displayed.
Figure 1 Creating a lifecycle rule
- 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 Warm After (Days)
Do not select this parameter.
Transition to Cold 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.
Note- 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.
- The Historical Version appears only when the versioning is enabled or suspended for the bucket.
- 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.
- Click OK to complete the configuration.
- Method: Using Lifecycle Rules