[Chapter 20] 20.3 How to Make Backups with a Local Tape Drive
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-10-23T15:44:50Z

#

| Chapter 20 Backing Up Files |

## 20.3 How to Make Backups with a Local Tape Drive

As we said in article 20.2, making a backup is easy:

>     % cd
>     % tar c .

The cd command moves you to your home directory. You could back up any directory the same way.

The tar (20.1) command, which is an abbreviation of tape archive, copies the current directory (specified by the `.`) to the default tape drive. The `c` argument specifies the create mode of tar.

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.

### 20.3.1 Syntax of the tar Command

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.

Table 20.1: Common tar Key Letters
Key Letter | Function
--- | ---
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.

### 20.3.2 What Is the Name of the Tape Drive?

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 `8` to a `0`. You can also list the devices in the /dev directory and look for one that has the most recent usage:

    ut [ ]
    % ls -lut /dev/r[ms]t*

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 major and minor numbers (17.22) (using the ls -l command) and read the appropriate manual page, which can be found by searching through the possible entries using man -k or apropos (50.2):

>     % man -k mt
>     % man -k tape

### 20.3.3 More on Tape Names

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. [1] 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:

> [1] This is probably not what you want. You could use a new tape for each dump.

>     % cd dir1
>     % tar cf /dev/nrst8 .
>     % cd dir2
>     % tar cf /dev/nrst8 .
>     % cd dir3
>     % 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 `t` or `tv` instead of the `c` . Adding the `v` 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.

- BB

20.2 Make Your Own Backups |  | 20.4 Restoring Files from Tape with tar