Tarsnap on CentOS with Plesk Panel

jesse's picture

This is a basic setup for using Tarsnap to backup a CentOS 6 server with Plesk Panel 11.

You can (and should) read elsewhere of issues with Tarsnap in general, such as slow restores, rotating archives and such. We're using Tarsnap for disaster recovery backups here, not primary backups. There are various scripts put together for rotating archives, look around for others is you prefer, this uses tarsnap-cron.

Build Evironment

Tarsnap is distributed as source code, so make sure you have the requisite build environment:

yum install openssl-devel zlib-devel e2fsprogs-devel gcc

Build and Install Tarsnap

You should check for the latest tarsnap version and adjust this as appropriate:

wget https://www.tarsnap.com/download/tarsnap-autoconf-1.0.35.tgz
sha256sum tarsnap-autoconf-1.0.35.tgz
tar xzf tarsnap-autoconf-1.0.35.tgz 
cd tarsnap-autoconf-1.0.35/
./configure
make; make install; make clean

Tarsnap config

Tarsnap needs a configuration file and a key generated to encrypt your backups.

cp /usr/local/etc/tarsnap.conf.sample /usr/local/etc/tarsnap.conf
sed -i 's|^keyfile .*|keyfile /etc/tarsnap.key|' /usr/local/etc/tarsnap.conf
echo 'exclude var/cache/*' >> /usr/local/etc/tarsnap.conf
echo 'exclude var/tmp/*' >> /usr/local/etc/tarsnap.conf
echo 'exclude tmp/*' >> /usr/local/etc/tarsnap.conf
tarsnap-keygen --keyfile /etc/tarsnap.key --user your@domain.com --machine `hostname -f`

backup your /etc/tarsnap.key now!

Stop right now and copy /etc/tarsnap.key somewhere safe! Your backups are useless without this file.

uuencode /etc/tarsnap.key `hostname -f`-tarsnap.key | mail -s "tarsnap key for `hostname -f`" your@domain.com

tarsnap-cron

cd /usr/local/bin
wget https://github.com/jnorell/tarsnap-cron/raw/master/tarsnap-archive.sh
wget https://github.com/jnorell/tarsnap-cron/raw/master/tarsnap-prune.sh
chmod +x tarsnap-{archive,prune}.sh
wget -O /etc/tarsnap-cron.conf https://github.com/jnorell/tarsnap-cron/raw/master/tarsnap-cron.conf.sample
wget -O /etc/cron.d/tarsnap-cron https://github.com/jnorell/tarsnap-cron/raw/master/tarsnap.cron.d.sample

When making archives, tarsnap crosses filesystem boundaries, so if you backup the root directory, tarsnap-cron will include the contents of all the other archives in the "root" archive as well. You may or may not want that.

If you have any locations you want to exclude from the backup, put them in tarsnap-cron.conf EXTRA_PARAMETERS, or as an exclude= line in tarsnap.conf. This server stores backups in directories starting with /var/www/backup, which is excluded from tarsnap.

Be sure to increase the default BANDWIDTH=100000, as backups take a long time at 100kbps.

Edit /etc/tarsnap-cron.conf:

BACKUP_ARRAY=(
    etc=/etc
    home=/home
    www=/var/www
    root=/
)
 
BANDWIDTH=40000000
EXTRA_PARAMETERS="--maxbw-rate-up $BANDWIDTH --exclude '/var/backup*' --exclude '/var/www/backup*'"
PRESERVE_PATH=true

Tarsnap does not exclude tmpfs mounts, though we did cover /tmp above. You might check for other things that should be excluded as well; I missed the backups directory while setting this up and it cost probably $50 in transfer fees.

Tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.