---
title: "Lay out storage by owner and let rules · Agent Wranglers"
url: https://agentwranglers.se/playbook/files-and-media/storage-and-backups/storage-lifecycle
id: MED-47
level: Recommended
updated: 2026-10-22
build: a2a6bdfed830
tokens: 889
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Lay out storage by owner and let rules clean it

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Storage and backups](https://agentwranglers.se/playbook/files-and-media/storage-and-backups.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-22.

- ID: MED-47
- Level: Recommended
- Chapter: [Storage and backups](https://agentwranglers.se/playbook/files-and-media/storage-and-backups.md)
- Rule: Name every stored object by stage, owner and a random ID, with the stage as the first prefix. Let storage lifecycle rules delete what nobody needs.
- Check: Read the bucket's lifecycle settings with the provider's tool. It has a rule for quarantine, one for unfinished multipart uploads and, with versioning on, one for old versions. A listing finds no unfinished multipart upload older than 2 days.
- How: Use keys such as `files/shops/{shopId}/{fileId}`, never the user's file name. Lifecycle rules match the start of the key, so `quarantine/`, `files/` and `derived/` come first and each gets its own rule. Deleting an owner is then one prefix per stage, and names stay out of logs. Expire quarantine after 1 day and abort unfinished multipart uploads after 1 day, since their parts cost money and stay invisible. With versioning on, expire old versions after 30 days, or deletion never finishes. Move files nobody has read in 90 days to a cheaper class if your provider offers one. Take each stage's age limit from [Keep one retention schedule](https://agentwranglers.se/playbook/compliance/records-and-data-map/retention-schedule.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JSON example

```json
{
  "Rules": [
    { "ID": "quarantine", "Filter": { "Prefix": "quarantine/" }, "Status": "Enabled", "Expiration": { "Days": 1 } },
    { "ID": "unfinished-multipart", "Filter": {}, "Status": "Enabled", "AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 1 } },
    { "ID": "old-versions", "Filter": {}, "Status": "Enabled", "NoncurrentVersionExpiration": { "NoncurrentDays": 30 } }
  ]
}
```

## Sources

- [Amazon S3 lifecycle configuration elements](https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html)

## Related rules

- CMP-11 [Keep one retention schedule](https://agentwranglers.se/playbook/compliance/records-and-data-map/retention-schedule.md) in Compliance and governance
- MED-23 [Build documents in a background job](https://agentwranglers.se/playbook/files-and-media/generated-documents/document-jobs.md) in Files and media

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/files-and-media/storage-and-backups/storage-lifecycle">Agent Wranglers files and media playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Restore files and their records together](https://agentwranglers.se/playbook/files-and-media/storage-and-backups/restore-files-with-records.md)
- Next: [Store the same file once per owner](https://agentwranglers.se/playbook/files-and-media/storage-and-backups/dedupe-by-hash.md)
- [Storage and backups](https://agentwranglers.se/playbook/files-and-media/storage-and-backups.md)
