Written by John Reed
Automated backups are easy to set up and surprisingly hard to maintain. Left alone, they tend to accumulate quietly in the background until one day your storage quota is exhausted and you discover that “off-site safety” has turned into “off-site hoarding.”
If you store database dumps in Dropbox (whether via cron jobs, server-side sync, or tools like Dropbox-Uploader) you’ve probably seen this firsthand. Files pile up day after day, week after week, year after year, on and on … unless you intervene.
To solve that problem in a way that works across multiple servers and clients, I put together a small utility called Dropbox-Cleaner. It’s a lightweight Bash script that automatically prunes old backups from a Dropbox directory while ensuring you always retain a safe minimum number of recent files.
When “Set It and Forget It” Becomes “Set It and Regret It”
Backups are one of the few areas of infrastructure where success is measured by how boring everything feels. When nothing goes wrong, you never think about them at all. The downside is that retention policies are just as easy to forget as the backups themselves.
Many hosting environments generate nightly database dumps with filenames that include the date, something like:
dbname-2026.02.03.sql.gz
dbname-2026.02.04.sql.gz
dbname-2026.02.05.sql.gz
That pattern is convenient for humans and scripts alike, but it also means the number of files grows indefinitely unless something trims the backlog. Multiply that by multiple sites, staging environments, and long-lived projects, and you end up with thousands of compressed SQL files quietly occupying space.
Dropbox’s reliability makes this worse, not better. Nothing breaks loudly. Storage simply fills up until new uploads fail or syncing stops.
Cleaning at the Destination Instead of the Source
Some backup systems include retention controls, but in real-world agency or multi-server environments, those controls are rarely consistent. Different projects use different tools, legacy cron jobs outlive their original maintainers, and sometimes you don’t control the backup process at all.
In those situations, enforcing retention where the files ultimately land is often the most pragmatic solution. If every server pushes backups to a known Dropbox folder, a single cleanup step can keep things under control regardless of how the files were created upstream.
Dropbox-Cleaner takes exactly that approach. It doesn’t create backups, upload files, or talk directly to Dropbox’s API. Instead, it relies on the predictable naming convention of the files themselves. As long as the filename contains a date in the form YYYY.MM.DD, the script can determine age, sort backups from newest to oldest, and decide what to keep.
Safety First: Never Delete Too Much
Scripts that remove files deserve a healthy amount of paranoia. The goal isn’t simply to delete old backups but to do so in a way that preserves recovery options even if something upstream has gone wrong.
For that reason, Dropbox-Cleaner combines age-based pruning with a minimum retention floor. A backup will only be removed if it is both older than a configured number of days and not among the newest N files in the directory. That means even if backups stop running for a while, the script will never reduce your archive below a safe baseline.
Because the logic operates purely on filenames, it also avoids dependence on Dropbox metadata or API behavior. The script works anywhere Bash works, which makes it easy to deploy across disparate servers without additional tooling.
Examples
Basic
./dropbox_cleaner.sh -d /backups/SQL
Keep 60 days, minimum 10 backups:
./dropbox_cleaner.sh -d /backups/SQL -k 60 -m 10
Built on Top of a Great Existing Tool
The project was inspired by Dropbox-Uploader, a long-standing open-source utility that makes it trivial to interact with Dropbox from the command line. Many backup workflows already rely on it to push files off-site, so adding a complementary cleanup step felt like a natural extension.
This script is also about paying forward the value of tools like that. Open-source infrastructure often consists of small, focused utilities that solve one problem well and, in turn, enable countless others. When you build something useful on top of them, sharing it back with the community helps keep that ecosystem healthy.
Why a Plain Bash Script?
One of the design goals was zero friction. Every Linux server already has Bash, cron, and a filesystem. Introducing additional runtimes or dependencies would complicate deployment without adding meaningful benefit for such a narrowly scoped task.
The script can simply be copied onto a server, configured with the path to your Dropbox folder, tested with a dry run, and scheduled to run nightly after backups complete. Once in place, it requires essentially no maintenance.
A Practical Tool for Real-World Workflows
Dropbox-Cleaner was written with agency environments in mind, where a single team might manage dozens of client sites across multiple hosts. In those scenarios, consistency matters more than sophistication. A small, predictable tool that behaves the same everywhere is often preferable to a complex system that only works in ideal conditions.
By centralizing cleanup at the storage destination, you can standardize retention without touching each backup job individually. That makes it particularly useful for legacy systems or inherited projects where modifying the original backup process is risky or impractical.
Get the Script
If your Dropbox backups are growing faster than your storage plan, you can grab the script here: https://github.com/cre8llc/Dropbox-Cleaner
Review the README, test it against a sample backup folder, and then schedule it after your nightly backup job.
It’s intentionally simple, easy to audit, and designed to be adapted if your naming conventions or retention needs differ.
Backups Are Only Useful If You Can Keep Them
Having backups is non-negotiable. Managing them responsibly is what turns them into a real disaster-recovery strategy. Without retention, backups can eventually become just another problem waiting to happen.
Automating cleanup closes that loop. When creation and pruning are handled automatically, backups return to their rightful place: boring, invisible, and ready when you need them.