Skip to content

Tarsnap - deleting unwanted archive-files

Last revised 20 March 2020.


I backup my system with Tarsnap every night via crontab, using the following command to make files with date stamps.

tarsnap-exclude [any-files-not-to-backup] -c -f arcadiabackup-`date +%d-%m-%y`[data-to-backup]

After some days this produces archive-files of the following character as seen with tarsnap --list-archives.


(In practice, the files will not always be in the correct date order as they are in this example.)

The problem
After several months I ended up with over 100 archive files and this resulted in my paying for more space than I needed.*

*Actually, Graham Percival, the author of Tarsnap, has recently said that retaining old archives costs much less than you would expect.

Deleting many files manually is slow so I use a semi-automatic method which I now describe. (There are scripts for doing this and other things at However, I still use the method described here.)

My solution

(Note: my editor is vim. If you use a different editor, such as emacs, you'll have to adapt the steps for that.)

1. Make a list of all the archive-files and save it as, e.g., archivelist.

tarsnap --list-archives > archivelist

2. Make an executable script called, e.g. tarsnap-delete. It should contain the following lines initially:

tarsnap -d \

3. Import archivelist (made in Step 1) into tarsnap-delete.

It will now look something like this.

tarsnap -d \

(Note: no spaces between any of the lines.)

4. Now delete all the entries that you DON'T want to remove from the tarsnap archjve. E.g. in this case you might delete the newest two entries (arcadiabackup-131103 and arcadiabackup-131104).

5. You next want to insert -f before each remaining archive entry and append \ to each entry. In vim you can do it by recording a macro. The following string of commands starts recording the macro, inserts the necessary characters into the first entry, moves the cursor to the next entry (if any) and ends recording the macro.


(NB. the "0" is a zero.)

6. Test this. Put the cursor on the first line of the archive list (arcadia-backup-131101)
and issue @z.

This line should now read:

-f arcadiabackup-131101 \

and the cursor should be on the next line.

7. If it works, you can repeat the macro as many times as necessary with, for example, 40@z. (Don't worry about 'over-running'.)

8. You can now save and exit vim, after which executing the file tarsnap-delete will delete all the archive files you selected. (Double-check the file before running it because the changes are irreversible!)

Note: To save the macro to use again later, edit your .vimrc and insert the line:

let @z = '[macro here]'

Type the macro sequence as you did previously but without "qz" and "q". I precede each character with Ctrl-v although I'm not sure it's strictly necessary.

To run the macro in future, type @z.


No Trackbacks


Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
Form options