Next: Using Multiple Tapes, Previous: Blocking, Up: Media
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 Blocking.