Unix Backup and File Restoration

Introduction

Please read chapter 11 in the Nemeth book.
Remember: Computers and disk drives can be replaced, data on disk often cannot. The material you have online represents your companies most valuable form of intellectual property and must be protected.

Disk failure, while much less prevalent now, still happens and as the system administration it is your responsibility to gaurentee you have taken the needed precautions to recover. It is extremely important to let people know what your strategy is and to verify you can meet the expectations of your organization. State in writing what you can and cannot do and make sure your boss and the users you support understand this.

Historical Context

Over the years the computer industry runs in cycles, as technology to produce mass storage improves, the cost of disk space drops. Whereas 10 years ago the cost of 1 MB of disk storage averaged above $10 a MB, today that cost has fallen to under $.25 a MB (e.g. a 1GB drive selling for $229). This drop in cost has resulted in much more disk space being bought and placed online. For example, this past year my group has ordered over 50GB of new disk storage, Five years ago we survived on under 10 GB.

Unfortuneately archival capacity has not fallen in price as quickly. As administrators you can easily add disk space and out-strip your capacity to back up that disk space.

Types of Backup Media

Backup media has generally fallen into two categories. One category is tape media and the other is removal cartridge. Tape media is generally cheaper is cost and supports larger sizes; however, tape media does not easily support random access to information. Removal cartridge drives, whether optical or magnetic, do support random access to information; however they have lower capacity and a much higher cost per megabyte than tape media. Finally, optical drives generally retain information for a longer time period than tapes and may be used if a permanent archival is needed (side note: Nothing is permanent, if that is a requirement, you must consider ways to make additional backup copies and periodically check the media).

Among tape media, the two most common choices now are 4mm DAT (digital audio tape) and 8MM Video Tape. The 4mm tape supports up to 2GB of data on a single tape (with compression this can approach 8GB). The 8mm tape supports up to 7GB of data on a tape (with compression this can approach 25GB). Both of these technologies have been in existence since the late eighties and are relatively proven. However, while they changed the dynamic of backup at that their introduction they are now having problems keeping up with the growth in data to be backed up. One of the principal problems is speed. At their maximum they can backup about 300K bytes/sec or just under 1GB in an hour. That sounds wonderful till you have to backup 50 GB in a night!

Among cartridge media, optical is the most commonly used. WORM (write once read many) is the primary choice. Worm drives can store between 600MB and 10GB on a platter and have a throughput similar to cartridge tapes for writing data. Optical storage will last longer and supports random access to data. These features make optical storage useful for storing billing or record information. Coupled with a Jukebox for housing multiple optical platters this can be a good solution for certain types of data.

Many backup options out there:

tar
tape archive program, easy to use and transportable. has limit on file name size, won't backup special files, does not follow symbolic links, doesn't support multiple volumes.

advantage is that tar is supported everywhere. Also useful for copying directories

tar -cf . | ( cd /user2/directory/jack; tar -xBf -)
tar cvfb /dev/tape 20 .
tar xvf /dev/tape .

cpio
Copy in/out archive program, rarely used except on older System V type machines. Must be given a list of file names to archive. Use find to do this:

find . -print | cpio -ocBV > /dev/tape

reloading a archive from tape
cpio -icdv < /dev/tape

dump
dump (or rdump) reads the raw file system and copies the data blocks out to tape. dump is program that is generally used by most groups. One feature of dump is that dump (via rdump) can work across a network and dump a file system to a remote machine's tape drive. Dump cannot be used to back up just a specific directory. Thus for backup of a directory tree tar or cpio is better suited.

dump backs up all files in filesystem, or files changed after a certain date to magnetic tape or files. The key specifies the date and other options about the dump. Key consists of characters from the set 0123456789fuscdbWwn. Any arguments supplied for specific options are given as subsequent words on the command line, in the same order as that of the options listed.

If no key is given, the key is assumed to be 9u and the filesystem specified is dumped to the default tape device /dev/tape.

Dump uses level numbers to determine whether a full or partial dump should be done. The levels can be between 0 and 9.

Designing a Backup Strategy

In a perfect world you will have the resources necessary to backup all data on all disks each night. However, the norm is that this is not the case, if that is so then you should Ask yourself these questions:

If you must have gaurenteed access to data you might consider using some form of RAID disk storage. RAID storage, coupled with optical or tape backup can deliver near continuous uptime.

If you can live with some risk and don't have the tape capacity to back up all file systems each night then you must develop a backup rotation stragety. This strategy defines how you will use your tape resources to cover the data resources in your organization. For example, one form of backup rotation might be you completely backup a file system every other night, meaning in a worst case situation you could lose up to 2 days of work! Alternately, you may define a strategy where you do occasional complete file system backups (called a full backup) and each night backup information that has changed since some date (an incremental backup).

Under Unix, if you use the dump command to backup your file system you have alot of flexibility in defining this strategy. Dump gives you the ability to assign a level to each dump ranging from 0 through 9. A level 0 dump will backup all files on the filesystem. A level 1 dump will back up all files that have changed since the level 0 dump was last performed, a level 2 dump backs up all files since the last level 1 dump or level 0 dump.

(In class I will describe how this works pictorially). Understand Exhibit A on page 188.

The dump command has many options. A sample dump command would look like:
dump 0usdf 6000 54000 /dev/tape /users Where
0 - represent the dump level (0 through 9)
u - signifies to update the /etc/dumpdates file
s - is the size of the tape in feet
d - represents the density of the tape
f - represents the device to use for the dump
6000 - is the size parameter in feet
54000 - is the density parameter
/dev/tape - is the device to use
/users - is the filesystem to dump

Calculating the size parameter

This is the hardest thing to do. A good rule of thumb is to use this formula TAPE SIZE = 7 * d * s, if you know the tape size you can work backward to arrive at d and s.

Luckily the man pages for dump give you examples for most common drives. IRIX, added a dump parameter named C (note the capital letter) where you specify the capacity in 1024 byte blocks (thus 2GB is 2000000 ).

Tape Drive Basics

Most backup work is done to some form of magnetic tape media. As with disks or other media, to use a tape drive under Unix you must have device files defined for that device. Refer back to the notes on adding a scsi device if you have questions aboue this.

Most Unix systems will look for an environment variable named TAPE and use that. Also most systems create a hard link from /dev/tape to the actual device name also have a hard link for /dev/nrtape to the default device. If not, you will need to know which device you are using. Under SGI IRIX, tape devices are in /dev/mt/ and start with tps:
The special files are named according to this convention:

/dev/{r}mt/tpsd{nr}{ns}{s}{v}{.density}{c}
/dev/rmt/jagd{nr}{ns}{s}{v}{stat}{.density}

Where {nr} is the no-rewind on close device, {ns} is the non-byte swapping device, {s} is the byte swapping device, and {v} is the variable block size device (supported only for 9 track, DAT, DLT and 8 mm devices as shipped). Density is tape density or type of device it is emulating (e.g. exabyte 8200 or exabyte 8500).

Unix creates multiple device files for the same tape device to handle different types of functions. NR means that the tape will not rewind when you close the tape device, this is needed if you want to place multiple files on a tape, one after another. NS means non-byte swap and is used by default, S is the byte swap device and is used when making tapes for machines such as sun systems. V allows variable block sizes to be written and requires a special tape device. Density is the type of tape device you are using and helps determine maximum size.

Restoring Files

Hopefully this won't have to happen but you need to be prepared. However, in practice something always arises to require a restore. To restore an entire file system you must remake the file system (mkfs, mount), then cd to that file system and run the command restore -r. If you have multiple levels of the file system restore will restore the files in reverse order of when they were dumped.

To restore just one file, use the restore command in interactive mode. This is done with the command restore -i. In interactive mode, you use the basic unix commands to navigate on the restore tape and then use the sub-command add filespec to add that file to the list to be extracted. When complete, use the command extract to have restore load in the files from tape. Add a directory to the list also causes all of the files within that directory to be added.

The book gives a nice treatment of this on page 194.

Basic Tape Commands

Basic tape operations are performed with the mt command.
mt [-t /dev/tapename] command [count]
*** commands ***
weof - Write [count] end-of-file marks
wsetmk - Write [count] set marks
fsf - Space forward [count] file marks
fsr - Space forward [count] records
bsf - Space backward [count] file marks
bsr - Space backward [count] records
spsetmk - Space [count] set marks
rewind - Rewind tape device
sppart - Space to partition 'count'
mkpart - Create two partition tape; first is 'count' Mbytes long
retension - Retension tape
feom - Space to end of data
offline - Take tape offline
unload - Unload tape from drive
erase - Erase from current position to EOT
exist - Exit status 0 if tape exists
status - Read tape status
blksize - Return default tape block size
setblksz - Set block size for some scsi tapes
recerron - Enable recoverable error reporting
recerroff - Disable recoverable error reporting
sili - Suppress illegal length indicator
eili - Enable illegal length indicator
reset - Reset drive - resets SCSI bus for SCSI tape only
audio - Set audio (1) or data (0) mode for writing
seek - Seek to given block (program # in audio mode)
help - Help printout of this message

The mt command can be used to test the tape drive and verify the tape and drive can work togethor before you perform backups.

Other issues

Things to consider.