Using Amanda to Backup Your Linux Server
Novell Cool Solutions: Feature
By Brian Higgins
Reader Rating
from 9 ratings
|
Digg This -
Slashdot This
Posted: 2 Nov 2006 |
Contents:
- Background
- Installing Amanda
- Configuring Amanda
- Creating file and directories
- Preparing tapes for use with Amanda
- Checking the configuration
- Performing the backup
- Checking the backup
- Automating the backup
- Conclusions
Background
At Central College of Commerce here in Glasgow, Scotland, I was looking for an a robust backup and restore solution for our student email server based around SLES. I trawled the Internet looking at various open source solutions and finally settled on Amanda, originally written at the Computer Science Department of the University of Maryland (http://www.amanda.org/about.php).
Amanda is simple to use but tricky to configure. It is worth sticking with Amanda until you get a fully working system. Don't be put off by the lack of a slick GUI interface or the need to configure the software via a console shell, once it is configured Amanda does its job very efficiently.
Installing Amanda
Amanda is included in the SLES 9 and 10 distributions although not installed by default. To install Amanda, run YaST and select "Software" from the left-hand panel and "Manage Software" (SLES 10) or "Install and Remove Software" (SLES 9). Enter "amanda" in the search box and click on the "Search" button. Check the box next to amanda to select the package for installation.
Click on the "Accept" button to begin the installation. Click on the "Continue" button to resolve any dependencies that Amanda requires.
Once the installation has finished you will find a new user called "amanda" has been created on your system. This user runs the backup and other tools used by Amanda:
# grep amanda /etc/passwd amanda:x:37:6:Amanda admin:/var/lib/amanda:/bin/bash
Configuring Amanda
The configuration files for Amanda are stored in the /etc/amanda directory. Each configuration that you create goes into a separate directory within /etc/amanda. There is a sample configuration in the "example" directory that you can use as a jumping off point for configuring Amanda. Instead I followed the instructions that Craig Small gives on his web site http://small.dropbear.id.au to help me set up Amanda.
The first thing that you need to do is to determine the configuration of the tape drive that Amanda will be using. There is a list of tape configurations on the Amanda website at http://amanda.sourceforge.net/fom-serve/cache/45.html. If your tape drive is not in this list then don't worry. Amanda provides a little utility called "amtapetype" that writes data to your tape drive to determine that capacity and speed of your drive. Be warned, this utility takes some time to run (in my case 3 hours) and destroys the content of the tape that you are using. To run the utility type:
# amtapetype –f /dev/nst0Where /dev/nst0 is the device driver used by your tape drive. You must use the no-rewinding tape device. When the utility finished it will print out a tape configuration for your tape drive in a format required by the Amanda configuration file. Make sure that you copy the output down before proceeding otherwise you will have to run the amtapetype utility again. My tape produced:
define tapetype unknown-tapetype {
comment "just produced by tapetype prog (hardware compression on)"
length 17021 mbytes
filemark 403 kbytes
speed 1491 kps
}
Now that you have the tape type identified you must create a directory within /etc/amanda to store your backup configuration. The name of the directory will be used by Amanda to identify the particular configuration. For our purposes I created a directory called "fullback" to store the configuration for a full backup of the system.
# mkdir /etc/amanda/fullback # chown amanda.disk /etc/amanda/fullback
In this directory create the amanda.conf file.
# vi /etc/amanda/fullback/amanda.conf
Below is a copy of our file:
org "Central College of Commerce" # Title of report
mailto "root" # recipients of report, space separated
dumpuser "amanda" # the user to run dumps under
inparallel 4 # maximum dumpers that will run in parallel
netusage 600 # maximum net bandwidth for Amanda, in KB per sec
# a filesystem is due for a full backup once every day
dumpcycle 0 days # the number of days in the fullback dump cycle
tapecycle 10 tapes # the number of tapes in rotation
runspercycle 1 # daily full backups
runtapes 1
bumpsize 20 MB # minimum savings (threshold) to bump level 1 -> 2
bumpdays 1 # minimum days at each level
bumpmult 4 # threshold = bumpsize * (level-1)**bumpmult
tapedev "/dev/nst0" # Linux @ tuck, important: norewinding
tapetype HPDAT-40 # what kind of tape it is (see tapetypes below)
labelstr "^FULLBACK-[0-9][0-9]*$" # label constraint regex: all tapes must match
diskdir "/var/tmp/amanda" # where the holding disk is
disksize 2000 MB # how much space can we use on it
infofile "/var/lib/amanda/fullback/curinfo" # database filename
logfile "/var/log/amanda/fullback/log" # log filename
indexdir "/var/lib/amanda/fullback/index"
define tapetype HPDAT-40 {
comment "HP StorageWorks DAT40 USB"
length 17021 mbytes
filemark 403 kbytes
speed 1491 kps
}
define dumptype root-tar {
program "GNUTAR"
comment "root partition dump with tar"
options index, exclude-list "/etc/amanda/fullback/fullback.exclude"
priority high
}
The "dumpcycle", "tapecyle", "runspercycle" and "runtapes" values depend upon the particular backup strategy. Our backup strategy is to do a full backup nightly Monday to Friday with two weekly sets of tapes for the backup. There is a useful perl script created by Kurt Yoder that calculates these values for your backup requirement at http://amanda.sourceforge.net/fom-serve/cache/391.html.
"labelstr" is a regular expression that describes the tape labels used by Amanda. All tape labels have to match this expression otherwise Amanda will refuse to use the tape. Our tapes are labeled "FULLBACK-01" .. "FULLBACK-10".
"diskdir" is where Amanda temporarily stores its files before writing them to tape.
The "infofile", "logfile" and "indexdir" entries point to the files used by Amanda to store database and log files.
The "define dumptype root-tar" entry describes a backup type and how it will be performed. The "root-tar" label will be used in a file called "disklist" to determine how to backup a particular partition or portion of the file system. You can define different types of backup for different parts of the file system. In this case I am using gnutar to archive the data and that file types or directories to be excluded are stored in a file called "fullbackup.exclude".
The "disklist" file, created in the same directory, contains one line:
localhost / root-tar
There are three fields in each line of the file. The first identifies the server (localhost), the second, the part of the file system to backup (/) and the third, the type of backup to perform (root-tar – defined in amanda,.conf).
You can break up your backup into smaller, more manageable chunks by putting separate entries into the "disklist" file. For example, the following configuration could be used to back up the home, opt and var directories:
localhost /home root-tar localhost /var root-tar localhost /opt root-tar
The "fullbackup.exclude" file identifies files or directories that should be ignored from the backup set.
/proc cache/man/man tmp
Creating file and directories
Before Amanda can successful back up your system it needs some file and directories to be created with the appropriate permissions set. The following commands assume that your configuration is called "fullback" and that the destination directories for logs and databases are as described in the "amanda.conf" file:
# chmod 770 /etc/amanda/fullback # touch /etc/amanda/fullback/tapelist # chown amanda.disk /etc/amanda/fullback/* # chmod 700 /etc/amanda/fullback/* # touch /var/lib/amanda/amandates # chown amanda.disk /var/lib/amanda/amandates # mkdir /var/lib/amanda/fullback # mkdir /var/lib/amanda/fullback/index # chown -R amanda.disk /var/lib/amanda/fullback # chmod -R 770 /var/lib/amanda/fullback # mkdir /var/log/amanda/fullback # chown amanda.disk /var/log/amanda/fullback # chmod 770 /var/log/amanda/fullback
Preparing tapes for use with Amanda
Amanda is very particular about tape labels and the sequence. Before using a tape you will have to label it with the "amlabel" utility. This utility must be run by the amanda user. Use "su" to change to the amanda user before running the program.
# su amanda > amlabel fullback FULLBACK-01 rewinding, reading label rewinding, writing label FULLBACK-01, checking label, done.
If the tape has previously been given a label the amlabel utility will refuse to change the label (in case you have put in the wrong tape). Use "amlabel –f" to force the label to be rewritten to the tape.
Checking the configuration
Before committing your data to the backup run the "amcheck" program to see make sure that there are no errors in your configuration file. Like amlabel, amcheck has to be run by the amanda user:
> amcheck normal Amanda Tape Server Host Check ----------------------------- Holding disk /var/tmp/amanda: 72525188 KB disk space available, that's plenty NOTE: skipping tape-writable test Tape FULLBACK-04 label ok Server check took 10.660 seconds Amanda Backup Client Hosts Check -------------------------------- Client check: 1 host checked in 10.063 seconds, 0 problems found (brought to you by Amanda 2.4.4p2)
Performing the backup
If amcheck ran without errors then it is time to run the first backup. Put the first tape in the drive and type:
# su amanda > amdump fullback
After a period of time Amanda will email you with the results of the backup operation.
Checking the backup
It is always a good idea to check your backup tapes to make sure that you can read the data back from them. Just because the backup program told you that it successful completed the operation does not mean to say that your data can be read back reliably. To restore files from an archive use the "amrecover" utility. Before running this utility, change to the /tmp directory so that the recovered files are stored there and do not overwrite the original files.
The amrecover utility gives you a sort of reduced shell and a command prompt. Using this shell we can tell the program what to restore. First of all we have to tell the recovery program which dataset within the dislist file we will be using. Since I only have one, the root partition, I set that to be the one to use with the command "setdisk /". Now I can navigate around the data set looking at the backed up files. You can use "cd" and "ls" to examine the stored data. To add files to be recovered from the backup use "add <filename>". Finally use "extract" to start the operation. At any point type "help" to get a list of available command. The following shows a dialog between myself and amrecover. My responses are in bold type:
# amrecover fullback AMRECOVER Version 2.4.4p2. Contacting server on localhost ... 220 mailstudent AMANDA index server (2.4.4p2) ready. 200 Access OK Setting restore date to today (2006-10-26) 200 Working date set to 2006-10-26. Scanning /var/tmp/amanda... 200 Config set to fullback 200 Dump host set to localhost amrecover> setdisk / 200 Disk set to /home. amrecover> cd /home/brian /home/brian amrecover> ls 2006-10-26 Desktop/ 2006-10-26 Documents/ 2006-10-26 bin/ 2006-10-26 mbox 2006-10-26 backup.sh 2006-10-26 phpmailer.tar 2006-10-26 public_html/ amrecover> add backup.sh added /home/brian/backup.sh amrecover> extract Extracting files using tape drive /dev/nst0 on host localhost. The following tapes are needed: FULLBACK-01 Restoring files into directory /var/tmp Continue [?/Y/n]? Y Extracting files using tape drive /dev/nst0 on host localhost. Load tape FULLBACK-01 now Continue [?/Y/n/s/t]? Y ./backup.sh amrecover> quit 200 Good bye
Automating the backup
If the recovery was successful then it is time to schedule the backup job via cron. I want to run the backup one minute passed midnight Monday to Friday:
# crontab –e 01 00 * * 1-5 /root/backup.sh
I use a script called "backup.sh" to perform the backup. I like to eject the tape after the backup so that the server is ready to accept the next tape. I use the following script to do this:
# Change to amanda user and run amanda dump program su amanda -c "/usr/sbin/amdump fullback" # Eject the tape sg_start /dev/st0 –eject
Conclusions
As I stated at the start of this document, Amanda is not easy to configure. It will probably take a few attempts before a working backup solution is in place but once it is up and running it is easy to schedule and use. Restoring a single file from a backup tape is a relatively easy process. There is plenty of support from online forums etc on the web. There are even a few Amanda based projects on http://sourceforge.net as well as a plug-in module for Webmin to manage Amanda. Overall I am very satisfied with the way Amanda works and I would encourage anyone who is looking for a backup solution for his/her SLES server to give Amanda a try.
Reader Comments
- Very good for quickstart thanks. /etc/xinetd/amanda file must be updated with "disable=no" in order to backup the localhost
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com


