Cleanup Policies

Cleanup policies are admin-defined rules that automatically delete objects on a schedule — retention, temp-file hygiene, and cost control without a cron box of your own.

s3bear.example.com
Cleanup policies screen
Define retention rules per bucket and tag from the Policies screen

What a policy specifies

  • Bucket patterns — a glob list (e.g. ["logs-*", "tmp-*"]).
  • Prefix filter — narrows the targeted keys (e.g. archive/2024/).
  • Older than days — only delete objects whose LastModified is older than this.
  • Cron expression — when to run.

Policies are backed by APScheduler with a PostgreSQL job store, so jobs survive restarts. Each run records last_run_at, last_run_status (success / partial / error), and last_run_deleted_count for observability. You can also trigger an ad-hoc run manually.

How to use

In the UI: Policies → New Policy.

# Create a policy: nightly delete files older than 30 days from any tmp-* bucket
curl -X POST http://localhost:8200/api/v1/policies \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "tmp-bucket-cleanup",
    "bucket_patterns": ["tmp-*"],
    "prefix_filter": null,
    "older_than_days": 30,
    "cron_expression": "0 3 * * *",
    "enabled": true
  }'

# Manual run
curl -X POST http://localhost:8200/api/v1/policies/{policy_id}/run \
  -H "Authorization: Bearer $TOKEN"

Use case: GDPR-compliant log retention

Compliance says raw access logs older than 90 days must be purged. Create a policy: pattern logs-access-*, older-than 90, cron 0 2 * * * (2 AM daily). It deletes anything past the retention window every night, and the audit log captures each deletion run for your auditors.

Use case: cleaning up CI build artifacts

Your CI pipeline drops a fresh artifact bundle into builds-pr/ for every pull request. PRs close, branches die, and the bucket grows forever. Policy: builds-pr/*, older-than 14, weekly cron. Two weeks after a PR is merged, its artifacts evaporate.


Related: Audit Log · Buckets & Quotas