-->
Page 377
The advantage of this backup scheme is that it requires only two sets of tapes. Restoring the full system from the level 0 backup and the previous evening's incremental can perform a complete restore. The negative side is that the amount backed up grows throughout the week, and additional tapes might be needed to perform the backup. Here is the second strategy:
Sunday | Level 0 backup |
Monday | Level 1 backup |
Tuesday | Level 2 backup |
Wednesday | Level 3 backup |
Thursday | Level 4 backup |
Friday | Level 5 backup |
Saturday | Level 6 backup |
The advantage of this backup scheme is that each backup is relatively quick. Also, the backups stay relatively small and easy to manage. The disadvantage is that it requires seven sets of tapes. Also, to do a complete restore, you must use all seven tapes.
When deciding which type of backup scheme to use, you need to know how the system is used. Files that change often should be backed up more often than files that rarely change. Some directories, such as /tmp, never need to be backed up.
A full backup with tar is as easy as
$ tar -c /
An incremental backup takes a bit more work. Fortunately, the find command is a wonderful tool to use with backups. The find command can be used to find all files that have changed since a certain date. It can also find files that are newer than a specified file. With this information, it is easy to perform an incremental backup. The following command finds all files that have been modified today, and backs up those files with the tar command to an archive on /dev/rmt1:
$ tar c1 `find / -mtime -1 ! -type d -print`
! -type d says that if the object found is a directory, don't give it to the tar command for archiving. This is done because tar follows the directories, and you don't want to back up an entire directory unless everything in it has changed. Of course, the find command can also be used for the cpio command. The following command performs the same task as the preceding tar command:
$ find / -mtime -1 | cpio -o >/dev/rmt1
As mentioned, the find command can find files that are newer than a specified file. The touch command updates the time of a file. Therefore, it is easy to touch a file after a backup has
Page 378
completed. Then, at the next backup, you simple search for files that are newer than the file you touched. The following example searches for files that are newer than the file /tmp/last_backup and performs a cpio to archive the data:
$ find / -newer /tmp/last_backup -print | cpio -o > /dev/rmt0
With tar, the same action is completed this way:
$ tar c1 `find / -newer /tmp/last_backup -print`
NOTE |
|
Backing up files is a good thing. But, backups are like an insurance policy. When it is time for them to pay up, you want it all, and you want it now! In order to get the files, you must restore them. Fortunately, it is not difficult to restore files with either tar or cpio. The following command restores the file /home/alana/bethany.txt from the current tape in the drive:
$ tar -xp /home/alana/bethany.txt $ cpio -im `*bethany.txt$` < /dev/rmt0
The -p in tar and the -m in cpio ensures that all the file attributes are restored along with the file. By the way, when restoring directories with cpio, the -d option will create subdirectories. The tar command does it automatically.
When you have a tape, you may or may not know what is on it. Perhaps you are using a multiple level backup scheme and you don't know which day the file was backed up. Both tar and cpio offer a way of creating a table of contents for the tape. The most convenient time to create this file, of course, is during the actual backup. The following two lines show how to perform a backup and at the same time create a table of contents file for that tape:
$ tar -cv / > /tmp/backup.Monday.TOC $ find / -print | cpio -ov > /dev/rmt0 2> /tmp/backup.Monday.TOC
The cpio backup automatically sends the list to standard error. Therefore, this line just captures standard error and saves it as a file. By the way, if the > in the tar command is replaced with the word tee, then the table of contents will not only be written to the file; it will also be printed to standard output (the screen).
Page 379
Backups are important, but being able to restore the files is more important. There is nothing that will cause the lump in the throat to appear faster than trying to restore a system, only to find that the backups failed. As with any administrative task performed on a system, backups require a good plan, proper implementation, good documentation, and lots of testing. An occasional spot check of a backup could save hours, if not days, of time.
Page 380
Page 381
In This PART
Page 382