Tarsnap Cleanup One-Liner

November 6 2016

Tarsnap is a pretty excellent tool and I use it to protect any VPS-like services where I do not have control over the backups. Ridiculously cheap, encrypted and runs flawlessly unsupervised. Hearty recommendation from me.

However, the UX leaves something to be desired, and this includes cleaning up old archives. Use it for a few years, and pretty soon you’ll find that you’re spending 10 cents/day on it.

There seem to be a few wrappers around Tarsnap that strive to improve its UX, however I found that they assume too much about my archive names, or they suffer from being terribly slow, e.g. running delete commands one invocation after the other.

If you want to delete all of the archives containing the string -2015 in them, with all potential speedups, then I suggest trying something like the following invocation:

tarsnap --list-archives | grep -- "-2015" | xargs bash -c 'echo "${@/#/-f }"' | xargs tarsnap -d

No doubt my bash-fu is weak here, but it works!