All posts
·Nov 11, 2026·3 min read

I asked for three backups. My retention rule would have kept one

#lessons-learned#automation#client-work#web-development

I look after seven WordPress sites, and every night my backend checks them, looks for updates, and takes backups. Until September a site could be in that fleet or deleted, nothing in between. That left no way to stop watching a site I no longer look after without also throwing away its credentials, its logs and its backups.

So I added a state for it: archived. Nothing runs against an archived site anymore, but the row, the logs and the backup history stay, so it can be brought back. The one thing I asked for on the backup side was simple. Stop making new ones, and keep three of the old ones: one recent, one from a while back, one from a while before that.

The rule I already had

The backend already had a retention rule that spoke that exact language. A policy says how many daily, weekly and monthly backups to keep, and the function that applies it, select_retained in services/retention.py, picks the newest backup from each of the last N days, weeks and months. Set it to 1/1/1 and you get three. That was going to be the whole change.

Then I read how the windows are measured. Every one of them counts back from now. For a site that still makes a backup every night, that is exactly right, because there is always a fresh archive inside each window. For a site that has stopped, the archives sit still while today keeps moving away from them. Within about a month every archive has fallen outside every window and the rule finds nothing to keep. A floor in the code makes sure a site never drops to zero, so it saves exactly one file, while the policy still reads 1/1/1 the whole time.

Changing the counts doesn't touch any of that, because every window, however many there are, still counts back from today.

Three backups with no clock

Archived sites now go through a second function, select_frozen, which never asks what day it is. It looks at the archives on disk and keeps:

  • the newest one
  • the newest one from a different ISO week
  • the newest one from a different calendar month

It returns the same three next year as it does today. The nightly retention sweep does the trimming, the same sweep that already deletes old backups. The archive request itself only returns a preview of what will go.

There was one more way back to the old behavior. A fleet-wide retention policy written for live sites could have widened an archived site's set again. Policy lookup for an archived site now short-circuits to the frozen rule before any policy row is read. A policy that names that one site specifically still wins, which is the escape hatch if a client ever wants a longer tail kept.

What it looked like on a real site

I archived one of my own sites to try it on September 25. The preview said the next sweep would drop 20 archives, about 3,516 MB, and keep one per day, week and month grain. That was one site. I resumed it before the sweep ran, and nothing was touched.

If you have a retention rule anywhere, backups, logs, snapshots, it's worth asking what it does to something that has stopped producing new copies. Anything phrased as "the last N days" is measured against today, and today doesn't stop.

While checking this I also found that the migration creating the per-site retention policy table had been written and never applied. Every sweep has been running on the config defaults, and archiving doesn't care because it never reads a policy row. As of September 25 the table was still missing. Tested September 2026.