As we said in article 20.2, making a backup is easy:
tar c .
The cd command moves you to your home directory. You could back up any directory the same way.
to the default tape drive.
argument specifies the
You might get an error. Something about device rmt8 off line. Don't worry. I exaggerated slightly when I said tar was easy to use. The tape device that SunOS tar uses by default is /dev/rmt8 (yours may be different). There are several types of tape units, and not all can be referred to using that name. Some system administrators will link that name to the actual device, which makes tar easier to use. But if that doesn't work, you need to specify additional arguments to tar.
Most UNIX commands follow a certain style when arguments are specified. tar does not follow this convention, so you must be careful to use tar properly. If the standard was followed, then the following might be an example of dumping the current directory to the 1/2-inch tape cartridge, verbose mode, block size of 20:
tapedump -c -v -b 20 -f /dev/rmt8 .Wrong!
Instead, all the flags are in the first argument, and the parameters to those flags follow the first argument, in order of the flags specified:
tar cvbf 20 /dev/rmt8 .
The same command can be specified in a different way by changing the order of the letters in the first argument:
tar cvfb /dev/rmt8 20 .
(Article 20.11 has diagrams and more information about the order of arguments.) The only key letter that has a fixed location is the first one, which must specify if you are reading or writing an archive. The most common key letters, and the functions they perform are listed in Table 20.1.
|c||Create an archive.|
|x||Extract files from an archive.|
|t||Table of contents.|
|v||Give verbose information.|
Some versions of tar require a hyphen (
-) before the letter.
Part of the difficulty in using tar is figuring out which filename to use for which device. The best way to find out is by asking your system administrator. If you can't, here are some ideas for Sun computers. If you have a 1/2-inch tape drive, try:
tar cf /dev/rmt8 .
If you have a 1/4-inch tape cartridge [or any drive connected by SCSI-JP ], try:
tar cf /dev/rst8 .
If this doesn't work, then try changing the
You can also list the devices in the
directory and look for one that has the most recent usage:
Some UNIX systems use different standards for naming magnetic tapes. There might be an h at the end of a name for high density. When in doubt, examine the (using the ls -l command) and read the appropriate manual page, which can be found by searching through the possible entries using :
man -k mt%
man -k tape
The names of tape devices typically start with an r, which suggests they are raw devices that do not support a filesystem. If the first two letters are nr, then this suggests a no-rewind operation. Normally the tape is automatically rewound when you are done. If you repeat the tar command, it will overwrite the first dump.  As this can waste large amounts of tape if the dumps are small, use the nr name of the tape to put several dumps on one tape. As an example, if you wanted to dump three separate directories to a 1/4-inch tape cartridge, you can type:
 This is probably not what you want. You could use a new tape for each dump.
tar cf /dev/nrst8 .%
tar cf /dev/nrst8 .%
tar cf /dev/rst8 .
Note that the third dump does not use the no-rewind name of the device, so that it will rewind when done.
To examine a tape without extracting any files,
get a table of contents and use the key letter
instead of the
flag gives a more verbose listing.
If you want to examine the third dump file, you can either use tar twice with the no-rewind names or skip forward one or more dump files by using the mt (magnetic tape) command to skip forward two. Be sure to use the no-rewind name:
mt -f /dev/nrst8 fsf 2
In some versions of tar, if you defined an environment variable TAPE:
setenv TAPE /dev/rst8
then you don't have to specify it for the mt or tar commands.