|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Using Prune to Manage Archives" |
| 4 | +date: 2023-07-02 00:00:00 -0400 |
| 5 | +category: "Service Setup" |
| 6 | +tags: ["linux", "backup"] |
| 7 | +--- |
| 8 | + |
| 9 | +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](https://github.com/BinaryPatrick/Prune) 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. |
| 10 | + |
| 11 | +## Install |
| 12 | + |
| 13 | +To install Prune you can go to the [releases page](https://github.com/BinaryPatrick/Prune/releases) and download the latest release for your environment. If you are running Linux on x64 you can also run the following commands to download and install Prune. |
| 14 | + |
| 15 | +```bash |
| 16 | +GITHUB_LATEST_VERSION=$(curl -L -s -H 'Accept: application/json' https://github.com/binarypatrick/prune/releases/latest | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') |
| 17 | +GITHUB_FILE="prune-linux-x64.tar.gz" |
| 18 | +GITHUB_URL="https://github.com/BinaryPatrick/Prune/releases/download/${GITHUB_LATEST_VERSION}/${GITHUB_FILE}" |
| 19 | + |
| 20 | +curl -L -o prune-linux-x64.tar.gz $GITHUB_URL |
| 21 | +tar xzvf prune-linux-x64.tar.gz ./prune |
| 22 | +sudo install -Dm 755 prune -t /usr/local/bin |
| 23 | +rm prune prune-linux-x64.tar.gz |
| 24 | +``` |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +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. |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +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. |
| 33 | + |
| 34 | +```bash |
| 35 | +prune --path /home/patrick/test/ --keep-last 10 --dry-run --verbose |
| 36 | +``` |
| 37 | +Example output: |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +You can also provide more file filtering using `--prefix` and `--ext`. |
| 42 | + |
| 43 | +```bash |
| 44 | +prune --path /home/patrick/test/ --keep-last 10 --prefix backup_ --ext tar.gz --dry-run --verbose |
| 45 | +``` |
| 46 | + |
| 47 | +Finally you can scope in the exact retention you want using the different retention interval filters. |
| 48 | + |
| 49 | +```bash |
| 50 | +prune --path /home/patrick/test/ --keep-daily 7 --keep-weekly 2 --dry-run --verbose |
| 51 | +``` |
| 52 | + |
| 53 | +So far I have tested this with Debian 12 and Raspbian and it runs great. |
| 54 | + |
| 55 | +Happy pruning! |
0 commit comments