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]vfdevice pattern
Now let’s look at some example commands. To create an archive
of a directory called pattern, use the command:
$tar cvfdevice pattern
To do the same thing, but with a blocking factor of 20, use the command:
$tar cvbf 20device 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 20device pattern
To create an archive of everything in the current directory starting with an “a”, use the command:
$tar cvfdevicea*
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access