Creating Incremental Backups with tar

As an example of an incremental backup system, consider creating a backup to a SCSI tape device (/dev/stO) using tar. For the purposes of this example, suppose the computer has four partitions: root (/), /home, /usr, and /var. The initial full backup might be accomplished with a command such as this:

# tar cvplf /dev/stO -listed-incremental /var/log/incr.dat I /home I usr /var

This command backs up all four partitions to /dev/stO. The -listed-incremental /var/log/incr.dat option tells tar to use /var/log/incr.dat as an index of previously backed-up files. When you run this command to create a full backup, this file should be empty or nonexistent; tar then populates it with a date code and information about each directory that's been backed up. If you later add files to a directory, tar can determine which files are new and back them up.

Tip You may want to use output redirection (>) to store the verbose output oftar in a file when backing up. This procedure will create a file that lists the contents of the backup, which can make it easier to locate files for restore. When you perform an incremental or differential backup, store the data to different files or use the appending output redirection operator (») so that you don't wipe out the full backup's file list.

To perform an incremental or differential backup, you type the same command you use to perform the full backup; however, how you handle the backup log file differs:

Incremental Backups Prior to making an incremental backup, you should make a copy of the initial incremental log file under a new name and refer to that copy when making the incremental backup. Alternatively, you could make an initial copy of the log file and then restore it after each incremental backup. In either case, the idea is to refer to the original backup log whenever you make a new backup, hence causing all files added or changed since that full backup to be included in the new backup.

Differential Backups The simplest way to perform a differential backup is to keep using the same backup command, including the same log file, for every backup. Each time you run the command, tar modifies the log file, so a new differential backup is created the next time you run the command.

If you want to mix backup types, you might need to create copies of the log file and restore them only at certain times. For instance, to create a new incremental backup once a week and daily differential backups, you'd copy the full backup's log file, use the original name every day, and restore the full backup's log file from the copy you made on a weekly basis.

One other factor requires attention: Placement of incremental or differential backups on the backup media. If you use a random-access medium such as a removable hard disk, you can place these backups in directories named after the dates of the backups. With tapes, you can use the mt command to skip over some backups. You would then use a non-rewinding tape device, such as /dev/nstO rather than /dev/stO, to access the tape. For instance, suppose you've created an initial full backup with the preceding command on Monday. On Tuesday, you want to create a differential backup using a fresh tape. You could use the same command to accomplish this task. On Wednesday, you want to create another differential backup on the same tape as you used on Tuesday, but without wiping out Tuesday's backup. You could type the following commands to accomplish this goal, after inserting the tape:

# tar cvplf /dev/nstO -listed-incremental /var/log/incr.dat I /home Iusr /var

The first of these commands probably isn't necessary, because most tape drives rewind the tape when you insert it. The second command tells the tape drive to skip over the first Hie. In this context, a tape file is a backup—think of it as a tar file stored directly on the tape. The third command is the backup command, but modified by using the non-rewinding device file, so as not to rewind the tape drive. The fourth command rewinds the tape and takes it offline. You could use the rewinding tape device (/dev/stO) instead of the non-rewinding one in the third command if you prefer; this would obviate the need for the fourth command, although this command does a bit more, such as ejecting the tape, on some tape drives.

For subsequent differential backups, you would increment the fsf counter in the second command—you'd make it fsf 2, fsf 3, and so on. These commands will skip over increasing numbers of backups. Of course, you must be careful not to exceed your tape drive's capacity.

Upon restore, you must mirror these commands; if you want to restore a file from the third backup file on a tape, you must precede the restore operation by an appropriate mt command, such as mt -f /dev/nstO fsf 2. When doing a full restore using differential backups, you can restore data one tape file at a time, and type mt -f /dev/nstO fsf 1 between each restore operation. You presumably don't want to skip any files, so the fsf number never exceeds 1; you just want to use this command to get the tape drive to read from the start of each new tape file.

Team LIB

Team LiB

^ previous

0 0

Post a comment