Skip to content

Instantly share code, notes, and snippets.

@wesort
Created February 27, 2024 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesort/7c0fc21f95cb4b37f8399a9b17b89ca6 to your computer and use it in GitHub Desktop.
Save wesort/7c0fc21f95cb4b37f8399a9b17b89ca6 to your computer and use it in GitHub Desktop.
Example for applying expiration policy on Digitalocean Spaces
<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Rule>
<ID>Prune files starting with backup- after 1 days</ID>
<Prefix>assets/backup-</Prefix>
<Status>Enabled</Status>
<Expiration>
<Days>1</Days>
</Expiration>
</Rule>
</LifecycleConfiguration>
@wesort
Copy link
Author

wesort commented Feb 27, 2024

Digitalocean Spaces is S3-compatible object storage

It is possible to set expiration policies for the stored files that they are deleted automatically based on rules.

The filesystem is not hierarchical, it is "flat". This means that folders within the Space aren't "directories", but rather an extended prefix of the filename.

Config:

  • Install s3cmd to interact with Spaces.
  • Create a lifecycle.xml text file (see above) and configure one or more <Rule> element(s)
  • The <Prefix> element tells the rule what to filter by.
    • Note: assets/ in this example is a "folder" in the Space.
  • Example (above): Any files in the assets/ folder where the filename starts with backup- will be deleted after 1 day.
  • Upload the policy with: s3cmd setlifecycle lifecycle.xml s3://wetest-dev-1
    • NB: wetest-dev-1 is the bucket's name
  • Check the policy with: s3cmd getlifecycle s3://wetest-dev-1
  • I found this helpful: hyperborea.org/tech-tips/s3-expiration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment