Tarsnap on OpenBSD

tarsnap is a nice online backup service where you pay only for actual data transfer. Currently you pay 0.30 USD / GB of transferred data. Tarsnap makes transfers efficient by using data from previous snapshots in a differential way.

Tarsnap is also designed after common tar utility, which makes adaption easier. After account setup and client installation a snapshot is transferred as as easy as.

tarsnap -cf home-peter-`date +%Y%m%d%H%M` /home/peter

Setup and account

First you need to setup an account at http://www.tarsnap.com/. In the process you will also transfer some money to cover for your traffic.

Installation on OpenBSD

You need to compile tarsnap on your architecture.

It's not available as a package because of the non-free license. But to install as a port is trivial. Its optional to install bzip2 and xc as packages, but it saves some compile time.

cd /usr
wget https://ftp.eu.openbsd.org/pub/OpenBSD/6.3/ports.tar.gz
tar xzf ports.tar.gz
cd ports/sysutils/tarsnap
pkg_add bzip2 xz
make install

It should be quite simple to compile from scratch as well.

wget --no-check-certificate https://www.tarsnap.com/download/tarsnap-autoconf-1.0.39.tgz
tar -xzf tarsnap-autoconf-1.0.39.tgz
cd tarsnap-autoconf-1.0.39.tgz
./configure --sysconfdir=/etc --mandir=/usr/local/man
make all install clean

The parameters supplied to configure is used to map the configuration file and manual pages to suitable locations in OpenBSD. See history of this article to see what I needed to do before I understood this.

Then you need to edit the configuration file (/etc/tarsnap.conf) to your needs. I changed some default values to adhere to my likings.

Then I create the key file. The password used at registration will be asked for. Note that archives is only accessible from this single machine if the key file is not copied to the other machine used.

tarsnap-keygen --keyfile /root/tarsnap.key --user <email> --machine `hostname`

KEEP THE tarsnap.key FILE IN A SAFE LOCATION AS THIS IS THE ONLY WAY TO GET ACCESS TO THE UPLOADED DATA!

I also chose another location for the tarsnap cache. /var/cache/tarsnap-cache instead of the default one. The complete /etc/tarsnap.conf is show below.

cachedir /var/cache/tarsnap-cache
keyfile /root/tarsnap.key
...

After this tarsnap is ready to be used ...

Usage

Tarsnap is used in the same way as tar is used. In the example below I first create a new snapshot of my home directory (this takes some time the first time), then list the archive and contents of the uploaded snapshot.

tarsnap -cf home-peter-`date +%Y%m%d%H%M` /home/peter
tarsnap --list-archives
tarsnap -tvf home-peter-201007182350

Add --keyfile <machine_tarsnap_key> if you want to access an archive from another machine.

Delete old archives.

tarsnap --list-archives | sort > archives.txt
cat archives.txt | grep nuc-20160* | awk '{print "tarsnap -d -f", $1}' > del-archives.sh
sh ./del-archives.sh

Or directly

tarsnap --list-archives | sort > archives.txt
cat archives.txt | egrep 201[67]..[123] | xargs -t -L 1 tarsnap -d -f

Or simpler

cat archives.txt | xargs -n1 tarsnap -df

Simple isn't it?

References