Web Analytics Made Easy -
StatCounter
Skip to content

Tarsnap - deleting unwanted archive-files

Last revised 18 November 2019



Introduction

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.


arcadiabackup-131101
arcadiabackup-131102
arcadiabackup-131103
arcadiabackup-131104

(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.

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 https://www.tarsnap.com/helper-scripts.html. 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:

#!/bin/sh
tarsnap -d \

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

It will now look something like this.

#!/bin/sh
tarsnap -d \
arcadiabackup-131101
arcadiabackup-131102
arcadiabackup-131103
arcadiabackup-131104

(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 making a macro. For example, put the cursor on the first line of the archivelist entries and type qz to start recording. Then issue the following command sequence:

(Esc)0i-f(Space)(Esc)A(Space)(Space)(Space)\(Esc)j

and finish recording with q. (NB. the "0" is a zero.)

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.

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

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

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

let @z = '[type macro here]'

To type the macro enter the same character sequence as you did previously. I precede each character with Ctrl-v although I'm not sure it's strictly necessary.

To run the macro in future, type @z.








Backing up with Tarsnap

I have to say that I'm mostly unhappy about putting important personal stuff on the "cloud". At the same time, the thought that everything might be lost if a disaster occurred here is not nice either. So recently I looked into several places for storing files but they all had difficulties of one kind another. Many didn't work for linux, and of those that did, either there were problems using them or the security was suspect, or both. One that seemed possible had a scheme for distributed storage on people's computers. Admittedly the files would be broken up and encrupted, but still I didn't like the idea. I wouldn't put my own stuff out there and I wouldn't want other people's files on my system.


Then I looked at Tarsnap (Online Backup for the Truly Paranoid), which is different. Security is at its heart and it doesn't even run on Windows (except with Cygwin)! It also has a very reasonable pricing system - you only pay for what you use. So if you are similarly thinking about off-site storage and you use Linux, OpenBSD, or FreeBSD, have a look at tarsnap.

From the tarsnap home page

Tarsnap is a secure online backup service for BSD, Linux, OS X, Minix, Solaris, Cygwin, and probably many other UNIX-like operating systems. The Tarsnap client code provides a flexible and powerful command-line interface which can be used directly or via shell scripts. ... With five minutes to download and install Tarsnap and $5 for an initial deposit, you can get started with Tarsnap today and stop worrying about whether your data is safe.