1

I try add expire days to a file and bucket but I have this problem:

sudo s3cmd expire s3://<my-bucket>/ --expiry-days=3 expiry-prefix=backup

ERROR: Error parsing xml: syntax error: line 1, column 0 ERROR: not found ERROR: S3 error: 404 (Not Found)

and this

sudo s3cmd expire s3://<my-bucket>/<folder>/<file> --expiry-day=3

ERROR: Parameter problem: Expecting S3 URI with just the bucket name set instead of 's3:////'

How to add expire days in DO Spaces for a folder or file by using s3cmd?

Oliver
  • 11,857
  • 2
  • 36
  • 42
Dmytro
  • 61
  • 2
  • 13

3 Answers3

4

Consider configuring Bucket's Lifecycle Rules

Lifecycle rules can be used to perform different actions on objects in a Space over the course of their "life." For example, a Space may be configured so that objects in it expire and are automatically deleted after a certain length of time.

In order to configure new lifecycle rules, send a PUT request to ${BUCKET}.${REGION}.digitaloceanspaces.com/?lifecycle

The body of the request should include an XML element named LifecycleConfiguration containing a list of Rule objects.

https://developers.digitalocean.com/documentation/spaces/#get-bucket-lifecycle

Community
  • 1
  • 1
Vitalii Zurian
  • 17,858
  • 4
  • 64
  • 81
1

The expire option is not implemented on Digital Ocean Spaces

Disova
  • 23
  • 1
  • 5
1

Thanks to Vitalii answer for pointing to API.

However API isn't really easy to use, so I've done it via NodeJS script.

First of all, generate your API keys here: https://cloud.digitalocean.com/account/api/tokens

And put them in ~/.aws/credentials file (according to docs):

[default]
aws_access_key_id=your_access_key
aws_secret_access_key=your_secret_key

Now create empty NodeJS project, run npm install aws-sdk and use following script:

const aws = require('aws-sdk');

// Replace with your region endpoint, nyc1.digitaloceanspaces.com for example
const spacesEndpoint = new aws.Endpoint('fra1.digitaloceanspaces.com');
// Replace with your bucket name
const bucketName = 'myHeckingBucket';

const s3 = new aws.S3({endpoint: spacesEndpoint});
s3.putBucketLifecycleConfiguration({
    Bucket: bucketName,
    LifecycleConfiguration: {
        Rules: [{
            ID: "autodelete_rule",
            Expiration: {Days: 30},
            Status: "Enabled",
            Prefix: '/', // Unlike AWS in DO this parameter is required
        }]
    }
}, function (error, data) {
    if (error) 
        console.error(error);
    else
        console.log("Successfully modified bucket lifecycle!");
});
Dmytro Rostopira
  • 10,588
  • 4
  • 64
  • 86