The FreeBSD 'zine

April 2000 : Systems Administration

Backing up FreeBSD Part 2
by David Lay <[email protected]>


This is the second in a series of articles dealing with data backup under FreeBSD. The first article offered some tips for sizing up your backup requirements and selecting appropriate backup media. This installment covers the basics of getting your tape drive working under FreeBSD. Future articles in this series will cover backup and recovery using several popular backup tools, including tar(1), dump(1) and Amanda.

Locating your tape device

There's several different tape drivers available under FreeBSD, each for a different type of tape drive. The different drive types are defined more by the type of interface supported than the actual tape media format. I was able to find three different drivers on my FreeBSD 3.4-RELEASE machine: sa for sequential access SCSI tape devices, wt for Archie/Wangtek tape drives, and wst for IDE/ATAPI tape drives. The device drivers for all except wst are also present in the GENERIC kernel installed with 3.4-RELEASE (those with ATAPI tape drives will need to perform some kernel configuration work before proceeding).

Once you've determined the appropriate tape device driver for your tape drive and made sure that driver is built into your kernel, the next step is to make sure that the kernel is detecting your tape drive during the boot sequence. You can check this by watching the device probe on the console during the boot sequence, or by using the dmesg(8) command on a running system to view the kernel's message buffer.

If your kernel is not able to discover your tape drive during the device probe, you should double check your kernel configuration file to make sure that the appropriate device driver has been built in to the kernel, and make sure your tape drive is properly connected to the appropriate interface and the power supply. This sort of troubleshooting is beyond the scope of this article.

I have a Seagate DDS-3 format SCSI tape drive attached to my system, so I'll be using the sa driver. This means that I need to look for devices called "sa<n>". For example:

	dave@disco:~ % dmesg
	Copyright (c) 1992-1999 FreeBSD Inc.
	Copyright (c) 1982, 1986, 1989, 1991, 1993
	        The Regents of the University of California. All rights reserved.
	FreeBSD 3.4-RELEASE #2: Fri Apr 14 20:18:49 EST 2000
	    [email protected]:/usr/src/sys/compile/DISCO
	Timecounter "i8254"  frequency 1193182 Hz
	Timecounter "TSC"  frequency 451024947 Hz
	Waiting 2 seconds for SCSI devices to settle
	sa0 at aha0 bus 0 target 6 lun 0
	sa0: <SEAGATE DAT 04106-XXX 735B> Removable Sequential Access SCSI-2 device 
	sa0: 3.300MB/s transfers
	dave@disco:~ % 

Tape device numbering

Tape devices are named and numbered in the same manner as most other devices under FreeBSD: the first device which uses the foo device driver is usually called foo0, the next is called foo1, and so on. Since my tape drive uses the sa driver, the first SCSI tape device found (ie. the SCSI tape device with the lowest SCSI ID on the lowest numbered SCSI bus) will be called sa0. If I had more than one SCSI tape drive attached, the subsequent drives would be called sa1, sa2, and so on (the device names can be hard-wired to specific SCSI device IDs on specific SCSI busses in the kernel configuration file if desired).

Now that we've confirmed that the kernel has located the tape devices we need to locate the device special files required for each tape device.

Tape device special files

Each tape device driver requires several device special files to be created in /dev to provide an interface between processes and the device. Most of the special files that would be needed in the most common configurations are already created as part of the normal FreeBSD installation. If you have more than two or more tape drives which use the same device driver, then you'll need to manually create the special files for the second and subsequent devices with MAKEDEV (beyond the scope of this article). Please read the FreeBSD Handbook for information on how to use MAKEDEV

Now that we know the device name of any attached tape devices we can verify that the device special files are present. Since my tape device is called sa0:

	dave@disco:~ % cd /dev
	dave@disco:/dev % ls -l *sa0*
	crw-rw----  2 root  operator   14,   2 Dec 29 13:55 ersa0
	crw-rw----  2 root  operator   14,   2 Dec 29 13:55 ersa0.0
	crw-rw----  1 root  operator   14,   6 Dec 29 13:55 ersa0.1
	crw-rw----  1 root  operator   14,  10 Dec 29 13:55 ersa0.2
	crw-rw----  1 root  operator   14,  14 Dec 29 13:55 ersa0.3
	crw-rw----  2 root  operator   14,   1 Apr 15 05:23 nrsa0
	crw-rw----  2 root  operator   14,   1 Apr 15 05:23 nrsa0.0
	crw-rw----  1 root  operator   14,   5 Dec 29 13:55 nrsa0.1
	crw-rw----  1 root  operator   14,   9 Dec 29 13:55 nrsa0.2
	crw-rw----  1 root  operator   14,  13 Dec 29 13:55 nrsa0.3
	crw-rw----  2 root  operator   14,   0 Dec 29 13:55 rsa0
	crw-rw----  2 root  operator   14,   0 Dec 29 13:55 rsa0.0
	crw-rw----  1 root  operator   14,   4 Dec 29 13:55 rsa0.1
	crw-rw----  1 root  operator   14,   8 Dec 29 13:55 rsa0.2
	crw-rw----  1 root  operator   14,  12 Dec 29 13:55 rsa0.3
	crw-rw----  1 root  wheel      14, 0x20000000 Dec 29 13:55 rsa0.ctl
	dave@disco:/dev % 

All the device special files shown above are for just the first SCSI tape device. In some ways, the SCSI tape driver is the most complex, so not all tape device drivers will require so many special files. More information about each specific tape driver can found in the man pages (e.g. man 4 wst).

Considering just the SCSI tape driver for now, we see that the special files listed above all have a similar naming convention. Ignoring the numbering, there are four different filenames: rsa0, nrsa0, ersa0, and rsa0.ctl. The purposes of these different files are summarised as follows:

special file name Purpose
rsa0 Rewind tape upon close
nrsa0 Don't rewind tape upon close
ersa0 Eject upon close
rsa0.ctl Control device (for examining device status)

All of these device special files access the same tape device, but the difference lies in the actions performed when the device file is closed. This may seem a little obtuse at first, but these subtle differences become important under particular circumstances. For example, if you wanted to write several backup images to the same tape in separate write operations (ie. closing the tape device between write operations) you would need to use the non-rewinding tape device special file. Otherwise, after you write the first image file, the tape will rewind to the beginning, and the second write operation will actually over-write the first.

Some backup software packages like to write several files to the same tape (to maximise tape utilisation). It's common for these backup images to be written periodically, days or weeks apart. If your backup software works this way, and you haven't configured this software to access the tape device via the non-rewinding device special file, you will be in for a nasty surprise when you go to restore files from last week's backup image. Similarly, you wouldn't want to use the ejecting device special file, since it would require manual intervention after each backup run to re-insert the tape into the drive. You should always make certain you understand how your backup software works, so that you can use the appropriate device special file to produce results that you expect.


That's all I've got time for in this installment. I had hoped to cover some simple low-level tape manipulation with mt(1) but I've pushed the deadline as far as I can. So in the next article I'll cover mt(1) and reading and writing files with dd.

Current Issue
. Issue #05 : June 2000

Old Issues
. Issue #01 : February 2000
. Issue #02 : March 2000
. Issue #03 : April 2000
. Issue #04 : May 2000

Quick Links
. Table of Contents
. Mailing Lists
. FreeBSD Events
. User Group Calendar
. Site Statistics
. Old Articles
. Latest News
. Press Releases
. Contribute
. Send us Feedback
. Other Resources
. Submit an Article
. Submit an Event

Today's Fortune

FreeBSD 'zine Poll
Are you going to BSDCon?
What the hell is BSDCon?
Results More polls

. VicFUG

. Issue #01 : Download
. Issue #02 : Download
. Issue #03 : Download
. Issue #04 : Download
. Issue #05 : Download


Runs on FreeBSD

Add Channel to My Netscape


Contact: <[email protected]>
This site and the tarballs are built every 6 hours.
Copyright � 1998-2000, The FreeBSD 'zine
Code revision: 06/15/2000��All rights reserved.