Saturday, March 08, 2008

Disk Based Backups With Amanda On Debian Etch

This document describes how to set up Amanda (The Advanced Maryland Automatic Network Disk Archiver) on Debian Etch. For this tutorial I chose Ubuntu v7.04 as a backup-client. The resulting system provides a flexible backup-system with many features. It will be able to back up multiple hosts via network to various devices. I chose the disk based backup for this howto.

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

1 Preparation

Set up a basic Debian system and a basic Ubuntu system - update both.

The Debian system will be the backup-host: server1.example.com.

The Ubuntu system will be the backup-client: server2.example.com.

2 Needed Packages On The Backup-Host

apt-get install amanda-server xinetd gawk gnuplot readline-common

3 Backup-Host Configuration

Note: I'm using the standard configuration DailySet1 in this howto.

3.1 Amanda.conf

We customize the amanda.conf for DailySet1 to our needs:

vi /etc/amanda/DailySet1/amanda.conf

Edit the following, existing lines, so that they look like this:

tapecycle 6 tapes
tapetype DISK
tpchanger "chg-disk"
changerfile "/etc/amanda/DailySet1/changer"
tapedev "file:/dumps/amandatapes/DailySet1"

Now add the tapetype definition for the virtual tapedevice. In this example I chose a size of 3GB for each virtual tape - resulting in a required space of 18GB for all six virtual tapes. Adjust it to your needs.

define tapetype DISK {
comment "Backup to HD"
length 3072 mbytes
}

Next we have to add a dumptype where we define the settings for the backups. But of course you can use the existing dumptypes. Make sure that you use/create one with the entry program "GNUTAR". All possible settings are well commented in the amanda.conf.

define dumptype example {
global
comment "example dumptype"
compress client fast
program "GNUTAR"
strategy standard
priority high
}

3.2 Virtual Tapedevice

First we have to prepare a directory-tree for amanda where the backups will be stored temporarily (the holding disk):

mkdir -p /dumps/amanda

Now we have to create a directory for the virtual tapedevice:

mkdir -p /dumps/amandatapes/DailySet1

In the next step we have to create the directories for the virtual tapes. In this example we create six virtual tapes:

for i in 1 2 3 4 5 6; do mkdir /dumps/amandatapes/DailySet1/slot${i}; done

Create the info file:

touch /dumps/amandatapes/DailySet1/info

Time to initialize the tapedevice by inserting the first virtual tape into the tapedevice:

ln -s /dumps/amandatapes/DailySet1/slot1 /dumps/amandatapes/DailySet1/data

Now we have to pass the ownership to the amanda-user:

chown -R backup:backup /dumps/

Next we switch to the user backup:

su backup

Note: All amanda-commands, except amrestore, have to be executed as user backup.

Create the tapelist file:

touch /etc/amanda/DailySet1/tapelist

We have to label the virtual tapes to make them usable for amanda:

for i in 1 2 3 4 5 6; do /usr/sbin/amlabel DailySet1 DailySet1-${i} slot ${i}; done

3.3 The Disklist

The disklist brings all together. Here we define what has to be backed up from what server with which settings. A complete entry for a server consists of the fqdn, the path (e.g. /var) or device (e.g. sda1) that shall be backed up and the dumptype.

vi /etc/amanda/DailySet1/disklist

server2.example.com /home example

Note: Don't forget to add the backup-client to /etc/hosts if you are using this setup in a LAN without an own DNS.

3.4 Amandahosts

Finally we have to edit the amandahosts file:

vi /etc/amandahosts

server1.example.com backup
server1.example.com root
server2.example.com root

4 Needed Packages On the Backup-Client

sudo apt-get install amanda-client xinetd openssh-server

5 Amandahosts On The Backup-Client

Add the backup-host to the amandahosts file.

sudo vi /etc/amandahosts

server1.example.com backup

Note: Don't forget to add the backup-host to /etc/hosts if you are using this setup in a LAN without an own DNS.

6 Scheduled Backups

Modify the existing crontab (crontab.amanda) in /etc/amanda on the backup-host to your needs.

7 Testing The Configuration On The Backup Host

/usr/sbin/amcheck DailySet1

should look like:

Amanda Tape Server Host Check
-----------------------------
Holding disk /dumps/amanda: 25063520 KB disk space available, using 24961120 KB
slot 1: read label `DailySet1-1', date `20070911'
NOTE: skipping tape-writable test
Tape DailySet1-1 label ok
Server check took 0.254 seconds
Amanda Backup Client Hosts Check
--------------------------------
Client check: 1 host checked in 0.354 seconds, 0 problems found
(brought to you by Amanda 2.5.1p1)

8 Manual Backup

For testing purposes or special reasons you can make a backup manually of course:

/usr/sbin/amdump DailySet1

Note: Depending on the size of the data this could take a while.

9 Restore Backups

Switch to a directory on the backup-host where you (temporarily) want to restore the backup file(s):

cd /tmp/

9.1 Select The Virtual Tape

Insert the virtual tape from which you want to restore the backup(s):

/usr/sbin/amtape $configuration slot $x

e.g.

/usr/sbin/amtape DailySet1 slot 1

9.2 Rewind The Virtual Tape

No joke, you have to rewind your HD. :)

/usr/sbin/ammt -t file:/dumps/amandatapes/$configuration rewind

e.g.

/usr/sbin/ammt -t file:/dumps/amandatapes/DailySet1 rewind

9.3 Restore Backup(s) From The Virtual Tape

To get all backups from the tape:

/usr/sbin/amrestore file:/dumps/amandatapes/$configuration

e.g.

/usr/sbin/amrestore file:/dumps/amandatapes/DailySet1

To get a single backup from the tape:

/usr/sbin/amrestore file:/dumps/amandatapes/$configuration $host $backed_path_or_device

e.g.

/usr/sbin/amrestore file:/dumps/amandatapes/DailySet1 server2.example.com '/home$'

or

/usr/sbin/amrestore file:/dumps/amandatapes/DailySet1 server2.example.com sda1

9.4 Transfer The Backup-File To The Client Host

I chose scp for this.

scp -C $backup_file $user@$backup-client:$destination_file

e.g.

scp -C server2.example.com._home.20070911.0 administrator@server2.example.com:/tmp/backup

9.5 Uncompress The Transfered Backup On The Client-Host

cd /tmp/
sudo tar xvf backup


No comments: