Backup with attic

For the last couple of years my backup system of choice has been Bup (https://github.com/bup/bup). It is based on git and handles incremental backups and deduplication by writing small chunks of checksummed data as git packfiles. In the beginning it was very fast and worked really well. Unfortunately you can’t remove data from bup and that has lead to a continuously growing backup database. These days the repository is really slow and when my last backup took 13 hours to complete I decided to look for an alternative.

My first option was to simply start using Bup from a clean database. Unfortunately I quickly ran into problems while executing the first backup. At random instances during the backup Bup was suddently unable to send some packages from my laptop to my backup server. I tried to restart the backup multiple times, I even reinitialised the backup on the server side but nothing helped. I finally gave up.

Then I started to look for alternatives and I soon discovered Attic (https://attic-backup.org/index.html). It supports reduplication just like Bup, but it also offers encryption AND you can remove old data from a backup set. Moreover it is easy to create independent backup repositories which is good because it keeps each database smaller which allows for better performance.

If you want to try out Attic, you can use my backup script as a starting point.

#!/bin/bash

set -e

IP=<ENTER YOUR SERVER IP>
USER=<Your server user>

year=2016

function backup()
{
   dir=$1
   name=$2

   BASE_PATH=/home/${USER}/attic/${year}
   SERVERURL=${USER}@${IP}

   ATTICDIR_PATH=${BASE_PATH}/${name}.attic
   REMOTE_FULL_SSHPATH=${SERVERURL}:${ATTICDIR_PATH}
   ARCHIVE=${REMOTE_FULL_SSHPATH}::`hostname`-`date +%Y%m%d-%H%M

   # Create dir if does not exist
   ssh $SERVERURL "mkdir -p ${BASE_PATH}"

   if ssh $SERVERURL "[ -d ${ATTICDIR_PATH} ]";
   then
      echo "Backing up $dir to $name"
   else
      echo "Creating $name for $dir"
      attic init ${REMOTE_FULL_SSHPATH} -e passphrase
   fi

   echo attic create --stats ${REMOTE_FULL_SSHPATH} ${dir}
   attic create --stats ${ARCHIVE} ${dir}
}

echo "Enter password: "
read -s pass

export ATTIC_PASSPHRASE=${pass}
echo

backup ~/Pictures "photos"
backup ~/Dropbox "dropbox"
backup ~/Desktop "desktop"
backup ~/Documents "documents"
backup ~/Development "development"
backup ~/Music "music"
backup ~/ownCloud "owncloud"

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s