Backing Up and Restoring with the tar Utility

tar is the most popular backup utility discussed in this chapter. Many of the files that you download from the Internet are in tar or compressed tar format. Although it usually isn’t used for daily backup and recovery, you are sure to find several uses for the tar utility .

Tip

As mentioned earlier, tar cannot preserve the access times of files that it backs up. If this is important to you, the GNU version of tar is able to do this.

Syntax of tar when Backing Up

The basic tar command is as follows:

$ tar [cx]vf 
                  device pattern

Now let’s look at some example commands. To create an archive of a directory called pattern, use the command:

$ tar cvf 
                  device pattern

To do the same thing, but with a blocking factor of 20, use the command:

$ tar cvbf 20 
                  device pattern

To do the same thing, but to have tar verify the data as it writes it (available only in GNU tar),[24] use the command:

$ gtar cvWbf 20 
                  device pattern

To create an archive of everything in the current directory starting with an “a”, use the command:

$ tar cvf 
                  device 
                  a*

The Options to the tar Command

tar has two great advantages. The first is the level of acceptance that it has received. The second is its short list of options—there really are not very many:

c

The c option tells tar to create an archive (to make a backup).

v

The v option tells tar to be verbose. It lists the name and size of each file as it is being archived.

W

The W option, available only in GNU tar, tells tar to attempt ...

Get Unix Backup and Recovery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.