- Table of Contents
- Copyright
- About the Lead Authors
- About the Contributing Authors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- I. Red Hat Linux Installation and User Services
- Chapter 1. Introduction to Red Hat Linux
- Chapter 2. Installation of Your Red Hat System
- Chapter 3. LILO and Other Boot Managers
- Chapter 4. Configuring the X Window System, Version 11
- Chapter 5. Window Managers
- Chapter 6. Connecting to the Internet
- Chapter 7. IRC, ICQ, and Chat Clients
- Chapter 8. Using Multimedia and Graphics Clients
- II. Configuring Services
- Chapter 9. System Startup and Shutdown
- Chapter 10. SMTP and Protocols
- Chapter 11. FTP
- Chapter 12. Apache Server
- Chapter 13. Internet News
- Chapter 14. Domain Name Service and Dynamic Host Configuration Protocol
- Chapter 15. NIS: Network Information Service
- Chapter 16. NFS: Network Filesystem
- Chapter 17. Samba
- III. System Administration and Management
- Chapter 18. Linux Filesystems, Disks, and Other Devices
- Chapter 19. Printing with Linux
- Chapter 20. TCP/IP Network Management
- Chapter 21. Linux System Administration
- Chapter 22. Backup and Restore
- Chapter 23. System Security
- IV. Red Hat Development and Productivity
- Chapter 24. Linux C/C++ Programming Tools
- Chapter 25. Shell Scripting
- Chapter 26. Automating Tasks
- Chapter 27. Configuring and Building Kernels
- Chapter 28. Emulators, Tools, and Window Clients
- V. Appendixes
- A. The Linux Documentation Project
- B. Top Linux Commands and Utilities
- C. The GNU General Public License
- D. Red Hat Linux RPM Package Listings
Backup Strategies and Operations
The simplest backup strategy is to copy every file from the system to a backup medium. This is called a full backup. Full backups by themselves are good for small systems.
The downside of a full backup is that it can be time-consuming. Restoring a single file from a large backup such as a tape archive can be almost too cumbersome to be of value. Sometimes a full backup is the way to go, and sometimes it is not. A good backup and recovery scheme identifies when a full backup is necessary and when incremental backups are preferred.
Incremental backups tend to be done more frequently. With an incremental backup, only those files that have changed since the last backup are backed up. Therefore, each incremental builds upon previous incremental backups.
UNIX uses the concept of a backup level to distinguish different kinds of backups. A full backup is designated as a level 0 backup. The other levels indicate the files that have changed since the preceding level. For example, on Sunday evening you might perform a level 0 backup (full backup). Then on Monday night you would perform a level 1 backup, which backs up all files changed since the level 0 backup. Tuesday night would be a level 2 backup, which backs up all files changed since the level 1 backup, and so on. This gives way to two basic backup and recovery strategies. Here is the first:
| Sunday | Level 0 backup |
| Monday | Level 1 backup |
| Tuesday | Level 1 backup |
| Wednesday | Level 1 backup |
| Thursday | Level 1 backup |
| Friday | Level 1 backup |
| Saturday | Level 1 backup |
The advantage of this backup scheme is that it requires only two sets of backup media. 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 media 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 media. Also, you must use all seven sets to do a complete restore.
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.
Performing Backups with tar and cpio
A full backup with tar is as easy as this:
$ tar cf backup.tar /
This example uses tar's f option, followed by the name of the desired backup archive and a designated directory tree to back up. Note that if you have a dual-boot system, and have Windows or another operating system available under the /mnt directory, those systems will also be backed up! You should also know that the GNU tar command can also perform on-the-fly compression using gzip by including the z option like this:
$ tar czf backup.tgz /
In this example, a compressed archive of the root directory is created and saved in the file named backup.tgz (also known as a compressed tarball). This is handy for creating single archives of known directories all at once.
An incremental backup takes a bit more work. Fortunately, the find command is a wonderful tool to use with backups 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 in the current directory (.) that have been modified today and backs up those files with the tar command to an archive on /dev/rmt1:
$ find . -mtime 1 ! -type d | tar cT - >/dev/rmt1
The ! -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, but for the entire filesystem (/):
$ 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 and may be used to touch a file after a backup has completed. Then, at the next backup, you simply 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:
$ find / -newer /tmp/last_backup | tar cT - >/dev/rmt0
Once you have found a reliable search command and determined a reliable destination for your backup, you can then automate the process by using a crontab setting. For example, one simple approach to back up the /home directory each day might be to place your command line (as an executable script) in the /etc/cron.daily directory. Red Hat Linux provides (by default) hourly, daily, weekly, and monthly operations in your system's /etc/crontab file, which looks like this:
... # run-parts 01 * * * * root run-parts /etc/cron.hourly 02 4 * * * root run-parts /etc/cron.daily 22 4 * * 0 root run-parts /etc/cron.weekly 42 4 1 * * root run-parts /etc/cron.monthly ...
If you take a look under the /etc/cron.daily directory, you'll see
001 0anacron logrotate makewhatis.cron slocate.cron tmpwatch 002
These files are executable shell scripts that are run (according to the /etc/crontab.daily entry) each day at 4:02 a.m. If your backup operations take too long and can possibly run into the morning work hours, you should adjust this setting, or create your own /etc/crontab entry, such as:
001 30 2 * * * /bin/tar cvzf /backup/daily.tgz /home 002
This example will back up the /home directory to the file named daily.tgz under the /backup directory each morning at 2:30 a.m.
Performing Backups with the taper Script
The taper script (/usr/sbin/taper), included with Red Hat Linux, is a backup and restore program with a graphical interface you can use to maintain compressed or uncompressed archives on tapes or removable media (even over a network!). Using taper is easy; the format of a taper command line looks like this:
# taper <-T tape-type> <option> <device>
You first need to decide what type of device (or media) you'd like to use with taper. This program supports a number of devices, which are listed in Table 22.2 along with the command lines to use.
Table 22.2. Device Support by taper
| Device | Type | Command Line |
| /dev/zftape | Floppy tape driver | # taper –T z |
| /dev/ht0 | IDE tape driver | # taper –T i |
| file | File on hard disk | # taper –T l |
| /dev/ftape | Floppy tape driver | # taper –T f |
| /dev/fd0 | Removable floppy drive | # taper –T r |
| /dev/sda4 | Removable Zip drive | # taper –T r –b /dev/sda4 (-b denotes the device and archive file) |
| /dev/sda | SCSI tape drive | # taper –T s |
After you start taper from the command line of your console or an X11 terminal window (you must be the root operator), you'll see a main menu of options to back up, restore, re-create, verify, set preferences, or exit, as shown in Figure 22.1.
Figure 22.1 The taper script offers a graphical interface to back up and restore operations for Linux.
Navigate through taper's menus with your up or down arrow keys and press the Enter key to make a selection. If you're not sure what keys to use, type a question mark (?) to have taper show a concise Help screen.
Start the backup process by selecting files or directories for your backup. First, highlight the Backup Module menu item and then press the Enter key. The taper script checks the status of the device you've specified on the command line and then looks for an existing tape archive on the device. If none is found, taper asks you to name the volume and then give a name for the new archive. You'll then see a directory listing similar to that in Figure 22.2.
Figure 22.2 The taper script offers selective backup and restoration of your directories or files.
Next, navigate through the listings or directories, using the i or I key to select files or directories to back up. When you finish, press the f or F key to start backing up your files. The taper script has many features and can be customized through preference settings in its main menu. For detailed information, see its documentation under the /usr/share/doc/taper-6.9b directory.
Restoring Files | Next Section

Account Sign In
View your cart