explain how to set per-directory TTL using the s3 api

Tom Crasset
2025-02-17 16:26:57 +01:00
parent e2d1e2656e
commit 4beff24f49
+37
@@ -52,3 +52,40 @@ rclone lsf seaweedfs:my-bucket/dir
```
If the directory `dir` exists in `my-bucket`, the orphaned metadata will be cleaned up. Note that due to slight API usage differences, `rclone ls` does not trigger cleanup, but `rclone lsf` will.
## Setting TTL
It is possible to set a TTL for a specific directory using the S3 API. They are set using [`PutBucketLifecycleConfiguration`](https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketLifecycleConfiguration.html).
Example of a JSON configuration is below. It is an equivalent of calling the following with `weed shell`.
```
fs.configure -locationPrefix /buckets/f341868e-baff-4e20-896a-08bc148e32f9/my-directory-whose-files-will-expire-in-20-days -ttl 20d -apply
```
:
```
{
"Rules": [
{
"Status": "Enabled",
"Filter": {
"Prefix": "my-directory-whose-files-will-expire-in-20-days"
},
"Expiration": {
"Days": 20d
}
}
]
}
```
Save that in a `.json` file and call it, for example, via the `aws` cli:
```
BUCKET_NAME=f341868e-baff-4e20-896a-08bc148e32f9
aws --endpoint-url http://127.0.0.1:8333 s3api put-bucket-lifecycle-configuration --bucket $BUCKET_NAME --lifecycle-configuration "file://lifecycle_policy.json"
```
Note that you don't need to add the part `/buckets/$BUCKET_NAME` in the configurations "Filter.Prefix" (contrary to using `fs.configure`, this is taken care of for you in the S3 API.