Scenarios
To save space and money, you can use OBS Console, the API, SDKs, OBS Browser+, or obsutil to delete unneeded objects.
The following describes how to manually delete objects. For details about the comparison between manual and automatic deletion, see Table 1.
Table 1 Object deletion methods
Method |
Description |
Rule |
Manual deletion |
Manual deletion is recommended for deleting a few or irregular objects. |
- Individual deletion
- Batch deletion
|
Automatic deletion |
To delete a large number of objects at a time or delete some objects periodically, you can configure lifecycle rules. |
In big data scenarios, parallel file systems usually have deep directory levels and each directory has a large number of files. In such case, deleting directories from parallel file systems may time out. To address this problem, you are advised to delete directories in either of the following ways:
- On the Hadoop client that has OBSA, an OBS client plugin, embedded, run the hadoop fs - rmr obs://{Name of a parallel file system}/{Directory name} command.
- Configure a lifecycle rule for directories so that they can be deleted in background based on the preset lifecycle rule.
Deleting Objects from a Bucket with Versioning Disabled, Suspended, or Enabled
Deleting objects may cause data loss. Exercise caution when performing this operation. Versioning can reduce the risk by restoring objects that are accidentally deleted or overwritten.
Scenario |
Deleting the Current Object Version |
Deleting a Noncurrent Object Version |
A versioning-disabled bucket |
OBS permanently deletes objects. Deleted objects cannot be recovered. |
N/A |
A versioning-suspended bucket |
- If an object's current version does not have a delete marker and its version ID is not null, the object deletion operation turns the current version into a noncurrent version and inserts a delete marker with an ID of null. The delete marker then becomes the current version.
- If an object's current version does not have a delete marker and its version ID is null, the object deletion operation inserts a delete marker with an ID of null that overwrites the current version. The delete marker then becomes the current version, and the overwritten version cannot be recovered.
- If the current version has a delete marker, no action is taken.
NOTE:
- After versioning is suspended, a newly uploaded object will have a version ID of null. If the newly uploaded object has the same name as an existing object with a null version ID, this new object will overwrite the existing object. For more information about versioning, see Versioning.
- By enabling Historical Versions in the object list, you can view the version ID of an object.
|
Deleted noncurrent versions cannot be recovered. |
A versioning-enabled bucket |
- If an object's current version does not have a delete marker, the object deletion operation inserts a delete marker. Then, the current version becomes a noncurrent version and the delete marker becomes the current version.
- If the current version has a delete marker, no action is taken.
NOTE:
- To permanently delete an object, delete it again from the Deleted Objects list.
- To recover a deleted object, undelete it from the Deleted Objects list. For details, see Undeleting an Object.
|
Deleted noncurrent versions cannot be recovered. |
Ways to Delete Objects
You can use OBS Console, APIs, SDKs, OBS Browser+, or obsutil to delete objects (folders included).
Using OBS Console
- In the navigation pane of OBS Console, choose Object Storage.
- In the bucket list, click the bucket you want to operate. The Objects page is displayed.
- Select the object or folder you want to delete and choose More > Delete on the right.
You can select multiple objects or folders and click Delete above the object list to batch delete them.
Figure 1 Deleting a file or folder
- Click OK to confirm the deletion.
Figure 2 Deleting objects
If you delete an object from a bucket with versioning enabled, the object is not permanently deleted but retained in the Deleted Objects list. All versions of the object are still kept in the bucket and are billed for storage. If you need to permanently delete the object, see the following steps.
- Permanently delete an object or a folder from an OBS bucket with versioning enabled:
- Enable Historical Versions.
- Select all the versions of the object to be permanently deleted and click Permanently Delete above the search bar.
Figure 3 Permanently deleting an object
- Click OK.
Using the GUI Tool - OBS Browser+
- Log in to OBS Browser+.
- Go to the bucket from which you want to delete a file or folder.
- Right-click the file or folder to be deleted and click Delete.
You can select multiple files or folders and choose More > Delete above the list to batch delete them.
- In the displayed dialog box, click Yes.
Using the CLI Tool - obsutil
Command Line Structure
- In Windows
- Deleting a single object
obsutil rm obs://bucket/key [-f] [-versionId=xxx] [-fr] [-o=xxx] [-config=xxx] [-e=xxx] [-i=xxx] [-k=xxx] [-t=xxx]
- Deleting objects in batches
obsutil rm obs://bucket/[key] -r [-j=1] [-f] [-v] [-o=xxx] [-config=xxx] [-e=xxx] [-i=xxx] [-k=xxx] [-t=xxx]
- In Linux or macOS
- Deleting a single object
./obsutil rm obs://bucket/key [-f] [-versionId=xxx] [-fr] [-o=xxx] [-config=xxx] [-e=xxx] [-i=xxx] [-k=xxx] [-t=xxx]
- Deleting objects in batches
./obsutil rm obs://bucket/[key] -r [-j=1] [-f] [-v] [-o=xxx] [-config=xxx] [-e=xxx] [-i=xxx] [-k=xxx] [-t=xxx]
Examples
- Take the Windows OS as an example. Run the obsutil rm obs://bucket-test/key -f command to delete a single object named key in bucket bucket-test.
obsutil rm obs://bucket-test/key -f
Start at 2024-09-25 04:48:10.1147483 +0000 UTC
Delete object [key] in the bucket [bucket-test] successfully, cost [152], request id [0000016979E1D2B2860BB5181229C72C]
Parameter Description
Parameter |
Optional or Mandatory |
Description |
bucket |
Mandatory |
Bucket name |
key |
Mandatory for deleting a single object.
Optional for deleting objects in batches. |
Indicates the name of the object to be deleted, or the name prefix of the objects to be deleted in batches.
NOTE:
If this parameter is left blank when deleting objects in batches, all objects in the bucket are deleted.
|
fr |
Optional for deleting a single object (additional parameter) |
Generates an operation result list when deleting an object. |
f |
Optional (additional parameter) |
Runs in force mode. |
versionId |
Optional for deleting a single object (additional parameter) |
Version ID of the object to be deleted. |
r |
Mandatory for deleting objects in batches (additional parameter) |
Deletes objects in batches based on a specified object name prefix.
CAUTION:
When you batch delete objects, all objects with the specified prefix will be deleted.
|
j |
Optional for deleting objects in batches (additional parameter) |
Indicates the maximum number of concurrent tasks for deleting objects in batches. The default value is the value of defaultJobs in the configuration file.
NOTE:
The value is ensured to be greater than or equal to 1.
|
v |
Optional for deleting objects in batches (additional parameter) |
Deletes versions of an object and the delete markers in batches based on a specified object name prefix. |
o |
Optional (additional parameter) |
Indicates the folder where operation result lists reside. After the command is executed, result lists (possibly including success and failure files) are generated in the folder. The default value is .obsutil_output, the subfolder in the home directory of the user who executes obsutil commands.
NOTE:
- The naming rule for result lists is as follows: rm_{succeed | failed}_report_time_TaskId.txt
- By default, the maximum size of a single result list is 30 MB and the maximum number of result lists that can be retained is 1024. You can set the maximum size and number by configuring recordMaxLogSize and recordBackups in the configuration file.
- If there are multiple folders and files and you need to confirm the detailed error information about a failed task, refer to the failure list rm_failed_report_time_TaskId.txt in the result list folder and the log files in the log path.
|
config |
Optional (additional parameter) |
User-defined configuration file for executing the current command. To learn the parameters that can be configured in this file, see Configuration Parameters. |
e |
Optional (additional parameter) |
Specifies the endpoint. |
i |
Optional (additional parameter) |
Specifies the user's AK. |
k |
Optional (additional parameter) |
Specifies the user's SK. |
t |
Optional (additional parameter) |
Specifies the user's security token. |
Response
Field |
Description |
Parallel |
Parameter -p in the request |
Jobs |
Parameter -j in the request |
Threshold |
Parameter -threshold in the request |
PartSize |
Parameter -ps in the request |
Exclude |
Parameter -exclude in the request |
Include |
Parameter -include in the request |
TimeRange |
Parameter -timeRange in the request |
VerifyLength |
Parameter -vlength in the request |
VerifyMd5 |
Parameter -vmd5 in the request |
CheckpointDir |
Parameter -cpd in the request |
OutputDir |
Parameter -o in the request |
ArcDir |
Parameter -arcDir in the request |
Succeed count |
Number of successful tasks |
Failed count |
Number of failed tasks |
Skip count |
Number of tasks that are skipped during incremental upload, download, or copy, and synchronous upload, download, or copy.
NOTE:
Skipped tasks are recorded into successful tasks.
|
Warning count |
Number of tasks that are executed successfully but contain warnings.
NOTE:
- The task for which a warning is generated may be a failure or a success, which needs to be further determined according to the corresponding result list.
- The number of tasks that generate warnings is independent of the number of successful or failed tasks. The total number of tasks is the number of successful tasks plus the number of failed tasks.
|
Succeed bytes |
Number of bytes that are successfully uploaded or downloaded. |
max cost |
Maximum duration of all tasks, in ms |
min cost |
Minimum duration of all tasks, in ms |
average cost |
Average duration of all tasks, in ms |
average tps |
The average number of tasks completed per second |
Task id |
Unique ID of an operation, which is used to search for the result list generated in a batch task |