When using tar as a backup utility, you need to do a few things with it. One option that is useful is to extract just one file. You can do this by specifying the name of the file as the argument to the -C option. For example, use tar -xvf /home.tar -C /home/hilary/noise.doc to extract only the noise.doc file from the tar archive.
Also useful is the option to exclude files from a backup. You can use tar to do that if you create an exclude file with the names of all the files you want to exclude in it. The content of the exclude file is just a plain list of files, and you can use any name you want for the exclude files. Listing 7-4 shows an example of an exclude file.
Listing 7-4. An Exclude File /boot/*
In this file, two directories and one specific file are excluded. To include the name of this file in the tar command when making the backup, use the -X option, for example: tar -cvf /dev/st0 / -X excludefile.
Like any other decent backup utility, you can use tar to make incremental backups as well. In an incremental backup, only files that have changed since the last backup will be backed up. To do this with tar, you first need to create a snapshot file. This snapshot file is created when creating the full backup with tar, and it basically lists all the files that have been backed up. To create the snapshot, you can use the -g option, for example: tar -cvg /backup/snapshotfile -f /backup/complete.tar /. This would make a complete backup of / and write that to the file /backup/complete.tar. A list of everything backed up is written to /backup/snapshotfile. To create an incremental backup the next day, you can use the same command: tar -cvg /backup/ snapshotfile -f /backup/complete.tar /.Because the snapshot file exists at that time, tar will not create it but use its contents to create an incremental backup. So when making a full backup with a snapshot file, make sure the name of the snapshot file does not exist already and always use a unique filename for it.
Was this article helpful?