[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.5 Many Archives on One Tape

Most tape devices have two entries in the ‘/dev’ directory, or entries that come in pairs, which differ only in the minor number for this device. Let's take for example ‘/dev/tape’, which often points to the only or usual tape device of a given system. There might be a corresponding ‘/dev/nrtape’ or ‘/dev/ntape’. The simpler name is the rewinding version of the device, while the name having ‘nr’ in it is the no rewinding version of the same device.

A rewinding tape device will bring back the tape to its beginning point automatically when this device is opened or closed. Since tar opens the archive file before using it and closes it afterwards, this means that a simple:

 
$ tar cf /dev/tape directory

will reposition the tape to its beginning both prior and after saving directory contents to it, thus erasing prior tape contents and making it so that any subsequent write operation will destroy what has just been saved.

So, a rewinding device is normally meant to hold one and only one file. If you want to put more than one tar archive on a given tape, you will need to avoid using the rewinding version of the tape device. You will also have to pay special attention to tape positioning. Errors in positioning may overwrite the valuable data already on your tape. Many people, burnt by past experiences, will only use rewinding devices and limit themselves to one file per tape, precisely to avoid the risk of such errors. Be fully aware that writing at the wrong position on a tape loses all information past this point and most probably until the end of the tape, and this destroyed information cannot be recovered.

To save directory-1 as a first archive at the beginning of a tape, and leave that tape ready for a second archive, you should use:

 
$ mt -f /dev/nrtape rewind
$ tar cf /dev/nrtape directory-1

Tape marks are special magnetic patterns written on the tape media, which are later recognizable by the reading hardware. These marks are used after each file, when there are many on a single tape. An empty file (that is to say, two tape marks in a row) signal the logical end of the tape, after which no file exist. Usually, non-rewinding tape device drivers will react to the close request issued by tar by first writing two tape marks after your archive, and by backspacing over one of these. So, if you remove the tape at that time from the tape drive, it is properly terminated. But if you write another file at the current position, the second tape mark will be erased by the new information, leaving only one tape mark between files.

So, you may now save directory-2 as a second archive after the first on the same tape by issuing the command:

 
$ tar cf /dev/nrtape directory-2

and so on for all the archives you want to put on the same tape.

Another usual case is that you do not write all the archives the same day, and you need to remove and store the tape between two archive sessions. In general, you must remember how many files are already saved on your tape. Suppose your tape already has 16 files on it, and that you are ready to write the 17th. You have to take care of skipping the first 16 tape marks before saving directory-17, say, by using these commands:

 
$ mt -f /dev/nrtape rewind
$ mt -f /dev/nrtape fsf 16
$ tar cf /dev/nrtape directory-17

In all the previous examples, we put aside blocking considerations, but you should do the proper things for that as well. See section Blocking.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.5.1 Tape Positions and Tape Marks

(This message will disappear, once this node revised.)

Just as archives can store more than one file from the file system, tapes can store more than one archive file. To keep track of where archive files (or any other type of file stored on tape) begin and end, tape archive devices write magnetic tape marks on the archive media. Tape drives write one tape mark between files, two at the end of all the file entries.

If you think of data as a series of records "rrrr"'s, and tape marks as "*"'s, a tape might look like the following:

 
rrrr*rrrrrr*rrrrr*rr*rrrrr**-------------------------

Tape devices read and write tapes using a read/write tape head—a physical part of the device which can only access one point on the tape at a time. When you use tar to read or write archive data from a tape device, the device will begin reading or writing from wherever on the tape the tape head happens to be, regardless of which archive or what part of the archive the tape head is on. Before writing an archive, you should make sure that no data on the tape will be overwritten (unless it is no longer needed). Before reading an archive, you should make sure the tape head is at the beginning of the archive you want to read. You can do it manually via mt utility (see section The mt Utility). The restore script does that automatically (see section Using the Restore Script).

If you want to add new archive file entries to a tape, you should advance the tape to the end of the existing file entries, backspace over the last tape mark, and write the new archive file. If you were to add two archives to the example above, the tape might look like the following:

 
rrrr*rrrrrr*rrrrr*rr*rrrrr*rrr*rrrr**----------------

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.5.2 The mt Utility

(This message will disappear, once this node revised.)

See section The Blocking Factor of an Archive.

You can use the mt utility to advance or rewind a tape past a specified number of archive files on the tape. This will allow you to move to the beginning of an archive before extracting or reading it, or to the end of all the archives before writing a new one.

The syntax of the mt command is:

 
mt [-f tapename] operation [number]

where tapename is the name of the tape device, number is the number of times an operation is performed (with a default of one), and operation is one of the following:

eof
weof

Writes number tape marks at the current position on the tape.

fsf

Moves tape position forward number files.

bsf

Moves tape position back number files.

rewind

Rewinds the tape. (Ignores number.)

offline
rewoff1

Rewinds the tape and takes the tape device off-line. (Ignores number.)

status

Prints status information about the tape unit.

If you don't specify a tapename, mt uses the environment variable TAPE; if TAPE is not set, mt will use the default device specified in your ‘sys/mtio.h’ file (DEFTAPE variable). If this is not defined, the program will display a descriptive error message and exit with code 1.

mt returns a 0 exit status when the operation(s) were successful, 1 if the command was unrecognized, and 2 if an operation failed.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by Sergey Poznyakoff on October, 20 2013 using texi2html 1.78.