Search This Blog

Monday, October 4, 2010

Script to perform tarsnapping of data on FreeBSD

Here is the script to perform tarsnapping on FreeBSD:


#!/bin/sh

# Directories to backup
DIRS=/usr/local/etc/tarsnap-backup.conf

#EXTRA_FLAGS=--dry-run

BACKUP=`date "+%Y-%m-%d+%H:%M"`
TARSNAP="/usr/local/bin/tarsnap"

# Do backups
IFS='
'
for dirs in `grep -v -e '^#.' $DIRS`; do
# Needs to set IFS to space to allow passing arguments to tarsnap
IFS=' '
echo ${dirs}
$TARSNAP $EXTRA_FLAGS -c -f $BACKUP-${dirs}
done


The conf file should look like:
archive_name1 /list /of /directories1
archive_name2 /list /of /directories2
misc /root /etc /boot/loader.conf /usr/local/etc /usr/local/opt /var/cron/tabs /var/services /var/mail /var/qmail/control /var/qmail/alias