Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Absolute BSD - The Ultimate Guide To FreeBSD (2002).pdf
Скачиваний:
25
Добавлен:
17.08.2013
Размер:
8.15 Mб
Скачать

Controlling Your Tape Drive

Tape drives have been around for many years, and the way FreeBSD handles them reflects that history. As with many old−fashioned UNIX devices, the way you access a tape drive controls how it behaves, and before you can use your tape drive for a backup you'll need to know how to control it. The most basic tape−control mechanism is the device node you use to access it.

Device Nodes

Device nodes, found in the /dev directory, are files that are tied to a physical device in your computer. You can use UNIX commands on the device node to control the hardware, but you shouldn't arbitrarily run commands on device nodes; doing something like cat /dev/console might not do anything, or it might damage your hardware or data. In most cases, device nodes have the same name or one similar to what appears in dmesg.boot.

Each type of tape drive has several device nodes, but for your average SCSI tape drive, you only need to worry about three nodes: /dev/esa0, /dev/nsa0, and /dev/sa0. Similarly, if you have an IDE drive, you only need concern yourself with /dev/east0, /dev/nast0, and /dev/ast0.

If you use the node name that matches the device name, the tape will automatically rewind when you're finished. For example, our sample SCSI drive is sa0, so if you run a command using /dev/sa0 as the device node, the tape will automatically rewind when the command finishes. Depending on the operating system you're used to, this might or might not match what you expect. Different versions of UNIX, with different tape management software, handle tapes differently.

REMEMBER Tapes are sequential access devices; data is stored on the tape linearly. To access a particular piece of data on a tape, you must roll the tape forward or backward. To rewind or not to rewind is an important consideration.

To have a tape eject automatically when you've finished with it, use the node that begins with "e". For example, if all you're doing is running a full system backup, you can use the /dev/esa0 device to automatically eject the tape after the job finishes. (Some older tape drives may not support automatic ejection; they'll require you to push the physical button to work the lever that winches the tape out of the drive The simplest way to find this out is to simply try it.)

If you don't want the tape to automatically rewind when you're finished (because you need to append a second backup from a different machine onto the tape, or something similar), stop it from rewinding by using the node name that starts with an "n". In our example, if you use /dev/nsa0 in your command, the tape drive will not rewind.

Using the TAPE Variable

Many programs assume that your tape drive is /dev/sa0, but that choice isn't always appropriate. Even if you have only one SCSI tape drive, you might not want it to automatically rewind upon completion (/dev/nsa0), or you might want it to eject after the backup (/dev/esa0). Or, you might have an IDE drive, which uses an entirely different device node.

Many programs use the environment variable $TAPE to control which device node they use, which you can always override on the command line. Most backup programs will use the device node specified in $TAPE as a default.

You can set the $TAPE variable with the following command:

50

...............................................................................................

# setenv TAPE /dev/sa0

...............................................................................................

Note Not all programs recognize $TAPE, but it's generally worth setting.

The mt Command

Once you know which device node you want to use to talk to your tape drive, you can make it do basic things (such as rewind, retension, erase, and so on) with mt(1). The mt command is most commonly used for checking the status of a tape drive, as follows:

...............................................................................................

# mt status

 

 

 

Mode

Density

Blocksize

bpi

Compression

Current:

0x25:DDS−3

variable

97000

DCLZ

−−−−−−−−−available modes−−−−−−−−−

 

 

0:

0x25:DDS−3

variable

97000

DCLZ

1:

0x25:DDS−3

variable

97000

DCLZ

2:

0x25:DDS−3

variable

97000

DCLZ

3:

0x25:DDS−3

variable

97000

DCLZ

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

 

 

Current Driver State: at rest.

 

 

 

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

 

 

File Number: 0 Record Number: 0

 

Residual Count 0

 

#

 

 

 

 

...............................................................................................

−−−−−−−−−−−−−−−− You won't need to worry about most of the information in this output, but if you want to go through it line−by−line, the mt(1) man page contains a good description of all the features. The first thing to note in this output is that mt can find your tape drive, which means that your system is set up properly to actually use the tape drive. (In this example, mt recognizes that the tape drive is a DDS−3.) The various "modes" shown are ways that the tape drive can run. Current Driver State tells you what the drive is doing at this moment.

The first time you run mt status, you might get something like this:

...............................................................................................

# mt status

mt: /dev/nsa0: Device not configured

...............................................................................................

This means that you don't actually have a tape device at the device node your $TAPE variable is set to. You can experiment with device nodes and mt(1) by using the −f flag to specify a device node (for example, mt −f /dev/nsa1 status), though you should get this information from dmesg.boot.

Other useful mt commands are mt rewind, mt offline, and mt retension. As you might guess, mt rewind rewinds the tape, mt offline ejects it, and mt retension tightens it by running it through its complete length, both forward and back. (Retensioning is often necessary because tapes tend to stretch on their first use; retensioning prestretches the tape before you write

51