Using Prune to Manage Backups
BinaryPatrick
Posted on July 4, 2023
Originally posted to binarypatrick.dev
Often times when using a tool like rsync to make backups you end up with lots of archives, and no way to keep them managed over time without a manual process. Prune is a simple tool that lets you remove prune archives in a folder, deleting any archives not matching the specified retention options. Any file type can be an archive and prune allows you to specify which files are in scope to be pruned.
https://github.com/BinaryPatrick/Prune
Install
To install Prune you can go to the releases page and download the latest release for your environment. You can also just clone the repo and compile it yourself with the steps in the readme. If you are running Linux on x64 you can also run the following commands to download and install Prune.
Don't just take my word for it. Always inspect the code that will be running on your machines, especially from an untrusted and unsigned source.
curl -s -o prune-install-linux-x64.sh https://raw.githubusercontent.com/BinaryPatrick/Prune/main/scripts/install-linux-x64.sh
chmod +x prune-install-linux-x64.sh
sudo ./prune-install-linux-x64.sh
rm prune-install-linux-x64.sh
Usage
Once it's installed, you should be able to run prune simply by typing in prune
, but don't. Prune is designed to delete things, and you should always run it with --dry-run
and --verbose
until you're certain what will be pruned.
To use prune, you will need to provide a pruning path and some retention value. Keep in mind prune is not recursive, so it will only purge files directly in the path you give. Prune also uses last modified date, not created date to evaluate what files to keep and prune. This allows for incremental backups with updates to be properly evaluated. You must specify some level of retention for prune to run.
prune --path /home/patrick/test/ --keep-last 10 --dry-run --verbose
Example output:
You can also provide more file filtering using --prefix
and --ext
.
prune --path /home/patrick/test/ --keep-last 10 --prefix backup_ --ext tar.gz --dry-run --verbose
Finally you can scope in the exact retention you want using the different retention interval filters.
prune --path /home/patrick/test/ --keep-daily 7 --keep-weekly 2 --dry-run --verbose
So far I have tested this with Debian 12 and Raspbian and it runs great.
Happy pruning!
Posted on July 4, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.