The Hidden Blog

As it turns out, I do have a hostname.

Backup your server with Tarsnap

Published on Feb 02, 2014

Regular and automated backups are hard to get right if you are not on a Mac using TimeMachine.

There are multiple ways to keep and maintain backups on a linux box (rsnapshot, rsync,...). I was searching for a service to create and store encrypted offsite backups which is reasonable cheap. I stumbled upon Tarsnap a number of times now and finally decided to give it a shot.

I just want to have a couple of revisions of a small number of directories in case of a hardware or user fail. Tarsnap's default script isn't covering the revision/rolling backup feature I need, that's why I'm using Tarsnap-generations. It's just a simple script to create new archives from a list of directories and prune old archives after a given timespan. Think of it as a rsnapshot for Tarsnap.

Note: This is not a tutorial, this is just to document my setup for future reference.

For it to work you'll need to set one parameter which isn't set in the default Tarsnap config so just create a .tarsnaprc in your ~ and add

humanize-numbers

You could also exclude some directories and files from your backup path. To do this just use the exclude parameter like this:

exclude /.ssh/
exclude /var/logs

The directories you want to backup should be added to a file called tarsnap.folders in your home directory. (If you are using the same cronjob from Tarsnap-generation's example on Github).

/home/dewey/.znc
/home/dewey/.zsh*
/var/www
/etc
/usr/share
/var/lib/bitlbee

If you manually run the script without waiting for a cronjob to run it, it'll look like this:

tarsnap: Removing leading '/' from member names
                                       Total size  Compressed size
All archives                               2.1 GB           638 MB
  (unique data)                            1.2 GB           371 MB
This archive                               6.2 kB           2.8 kB
New data                                   6.2 kB           2.8 kB
20140202-18-HOURLY-at-notmyhostname-/var/lib/bitlbee backup done.
Verifying backups, please wait.
20140202-18-HOURLY-at-notmyhostname-/var/lib/bitlbee backup OK.
Finding backups to be deleted.

Once the script ran you'll see all your archived backups with the tarsnap --list-archives command.

root@at-notmyhostname ~$ tarsnap --list-archives
20140202-18-HOURLY-at-notmyhostname-/home/dewey/.znc
20140202-18-HOURLY-at-notmyhostname-/home/dewey/.config
20140202-18-HOURLY-at-notmyhostname-/home/dewey/.zshrc
20140202-18-HOURLY-at-notmyhostname-/var/lib/bitlbee

Resources: