Web Analytics Made Easy -
Skip to content

Tarsnap - deleting unwanted archive-files

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 +%y%m%d` /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. See http://mail.tarsnap.com/tarsnap-users/msg01535.html.

You can delete files with a command such as:

tarsnap -d -f arcadiabackup-131201

When you have a lot of files to delete this will take a long time if you delete each one separately, and tarsnap doesn't allow the use of wildcards. But you can have more than one -f and this offers a quicker route.

I have worked out a semi-automatic method which I now describe. [Note added 15 March 2019: There are scripts for doing this and other things at https://www.tarsnap.com/helper-scripts.html.]

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

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 now want to insert -f before each remaining archive file. In vim you can do it like this:

:%s/arcadia/-f arcadia/g

Your file will now look like this:

tarsnap -d
-f arcadiabackup-131201
-f arcadiabackup-131102

6. Almost there! Now we just format all the entries into a single paragraph:


It will now look like this:

tarsnap -d -f arcadiabackup-131101 -f\

(Note: if you have a lot of entries, you will need to do

:set tw=1000

to avoid unwanted breaks in the command line.)

7. You can now save and exit vim, after which executing the file tarsnap-delete will delete all the archive files you selected.


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.
How many legs do snakes have?
Form options