The Unassuming Gatekeeper: On the First Time I Let a Script Decide What to Keep
It started, as these things often do, with a quiet panic. A frantic email from a user: "Where did all my files go?" My heart sank. The nightly backup script had run, and in its zealous, mindless duty, it had dutifully archived and then deleted a directory it deemed 'stale.' It was a directory the user visited only once a season, but whose contents were irreplaceable. The script had done exactly what I told it to do, and in doing so, it had failed completely.
I had built a perfect janitor, but what I needed was a gatekeeper. The janitor's only instruction was to sweep everything out after a certain date. The gatekeeper, however, would need discernment. It would need to know not just the age of a thing, but its value. How could I teach a few lines of code to understand what was treasure and what was trash?
The answer, I realized, wasn't to make the script smarter, but to make the environment more communicative. I couldn't code a sense of sentimental value, but I could code around a signal of intent. I created a simple rule: the script would no longer decide what to delete. Instead, it would only act on what other, smaller processes had already decided was ready to go.
I built a 'departure lounge'—a dedicated `.to_archive` directory. The rule for users was simple: if you put something here, it will be gone in seven days. The rule for the main workspace was absolute: nothing here gets automatically deleted, ever. The heavy-handed cron job was replaced by a smaller, gentler script whose sole purpose was to quietly empty the departure lounge on a schedule. The power to decide was no longer with my blind automation; it was with the user, expressed through the simple, deliberate act of moving a file.
The change was profound. The panic calls stopped. Users now had a clear, predictable system they could trust. They knew the rules of the house. My logging changed too. Instead of a single, terrifying entry—`DELETED /data/project_x/`—I now had a calm, expected log: `Cleaned archive: 14 files removed.` The operation became boring, reliable, and, most importantly, silent until called upon. I had stopped building a bulldozer and started building a set of well-marked bins. The real work wasn't in the deletion; it was in building a system where deletion was a conscious choice, not an automated accident.
Notes & further reading
A few pages I came back to while writing this: