Project Description

Backups are good for you. Most people learn this the hard way (including me).
Nowadays my Linux laptop automatically creates a full system snapshot every
four hours by pushing changed files to an rsync daemon running on the server
in my home network and creating a snapshot afterwards using the cp -al
command (the article Easy Automated Snapshot-Style Backups with Linux and
Rsync explains the basic technique). The server has a second disk attached
which asynchronously copies from the main disk so that a single disk failure
doesn’t wipe all of my backups (the “time delayed replication” aspect has also
proven to be very useful).

Okay, cool, now I have backups of everything, up to date and going back in
time! But I’m running through disk space like crazy… A proper deduplicating
filesystem would be awesome but I’m running crappy consumer grade hardware and
e.g. ZFS has not been a good experience in the past. So I’m going to have to
delete backups…

Deleting backups is never nice, but an easy and proper rotation scheme can help
a lot. I wanted to keep things manageable so I wrote a Python script to do it
for me. Over the years I actually wrote several variants. Because I kept
copy/pasting these scripts around I decided to bring the main features together
in a properly documented Python package and upload it to the Python Package
Index.

$ rotate-backups --help
Usage: rotate-backups [OPTIONS] DIRECTORY..
Supported options:
-H, --hourly=NUM how many hourly backups to preserve
-d, --daily=NUM how many daily backups to preserve
-w, --weekly=NUM how many weekly backups to preserve
-m, --monthly=NUM how many monthly backups to preserve
-y, --yearly=NUM how many yearly backups to preserve
-i, --ionice=CLASS use ionice to set the I/O scheduling class
-n, --dry-run don't make any changes, just print what would be done
-v, --verbose make more noise
-h, --help show this message and exit

The last section (see below) contains a real example that shows how rotation
frequencies can be combined.

The latest version of rotate-backups is available on PyPI and GitHub. For
bug reports please create an issue on GitHub. If you have questions,
suggestions, etc. feel free to send me an e-mail at peter@peterodding.com.