Set bucket trash
Application scenarios
When developers perform data storage and management in BOS, they usually expect better solutions for the following scenarios based on higher requirements for data reliability:
- When accidental deletions occur during data usage, a method for recovering the data should be available.
- When write permissions are granted to multiple users through a bucket's ACL, safeguards should be in place to prevent malicious deletion of bucket data by these users.
Operation types
To address such scenarios and enhance the data reliability of BOS, BOS introduces a bucket trash function. Bucket owners with Full Control permission can configure the bucket trash settings. These configurations can be performed through various methods, such as API or console, depending on your development preferences:
-
Managing the bucket trash via API:
- PutBucketTrash : Start the bucket trash function.
- GetBucketTrash: Check the current status of the bucket trash.
- DeleteBucketTrash: Disable bucket trash function.
-
For instructions on setting up the bucket trash through the console, please refer to Setting Up the Bucket Trash.
- Once the bucket trash function is enabled, users can find deleted bucket data in the bucket trash directory. The default path for this trash is Bucket/.trash/.
- To restore data in the bucket trash, directly rename the file in the bucket trash by removing the .trash/ path from its file name
- To permanently clear data in the bucket trash, directly delete the specific file under the .trash/ path again
Based on the second scenario mentioned above, you can also combine the bucket trash capability with bucket ACL. For example, for a user who needs Write permission in BucketA, configure the following ACL:
1{
2 "id": "policy_3563bce24f2049629f4e0b6bf7a2775d",
3 "version": "v1",
4 "grantee": [
5 {
6 "id": "b124deeaf6f641c9ac27700b41a350a8"
7 }
8 ],
9 "accessControlList": [
10 {
11 "service": "bce:bos",
12 "region": "bj",
13 "resource": [
14 "BucketA"
15 ],
16 "effect": "Allow",
17 "permission": [
18 WRITE"
19 ]
20 },
21 {
22 "service": "bce:bos",
23 "region": "bj",
24 "resource": [
25 "BucketA/.trash/"
26 ],
27 "effect": "Deny",
28 "permission": [
29 "DeleteObject"
30 ]
31 }
32 ]
33}
With the specified ACL, users can perform write and delete operations on the bucket but cannot permanently delete data from the bucket trash directory.
Note
- If the bucket trash function is enabled and the trash path is set to .trash/, deleting File A (original path: Bucket/test/A) will move it to Bucket/.trash/test/A. If the bucket trash function is later disabled, the file will remain at Bucket/.trash/test/A, so it's recommended to clean up such residual files as needed after disabling the feature.
- If the bucket trash function is enabled and the trash path is set to .trash/, deleted files will be moved to Bucket/.trash/. Changing the trash path to .trashX/ will result in newly deleted files being moved to Bucket/.trashX/, while files deleted earlier will remain in Bucket/.trash/. It's recommended to migrate the existing files as needed when changing the trash path.
- When deleting an archive storage class file, the archive storage class file will not be moved to the bucket trash and will be deleted directly.
Billing mode
- BOS does not impose extra charges for the bucket trash. Files in the trash are still counted as part of the bucket's data, and storage fees apply based on their storage class.
- Once files in the bucket trash are permanently deleted, storage fees for them will no longer be charged.
