9.2. Backup Programs

The three major programs are dump(8), tar(1), and cpio(1).

9.2.1. Dump and Restore

dump(8) and restore(8) are the traditional Unix backup programs. They operate on the drive as a collection of disk blocks, below the abstractions of files, links and directories that are created by the filesystems. dump(8) backs up devices, entire filesystems, not parts of a filesystem and not directory trees that span more than one filesystem, using either soft links ln(1) or mounting one filesystem onto another. dump(8) does not write files and directories to tape, but rather writes the data blocks that are the building blocks of files and directories. dump(8) has quirks that remain from its early days in Version 6 of ATT Unix (circa 1975). The default parameters are suitable for 9-track tapes (6250 bpi), not the high-density media available today (up to 62,182 ftpi). These defaults must be overridden on the command line to utilize the capacity of current tape drives.

rdump(8) and rrestore(8) backup data across the network to a tape drive attached to another computer. Both programs rely upon rcmd(3) and ruserok(3) to access the remote tape drive. Therefore, the user performing the backup must have rhosts access to the remote computer. The arguments to rdump(8) and rrestore(8) must suitable to use on the remote computer. (e.g. When rdump'ing from a FreeBSD computer to an Exabyte tape drive connected to a Sun called komodo, use: /sbin/rdump 0dsbfu 54000 13000 126 komodo:/dev/nrsa8 /dev/rda0a 2>&1) Beware: there are security implications to allowing rhosts commands. Evaluate your situation carefully.

9.2.2. Tar

tar(1) also dates back to Version 6 of ATT Unix (circa 1975). tar(1) operates in cooperation with the filesystem; tar(1) writes files and directories to tape. tar(1) does not support the full range of options that are available from cpio(1), but tar(1) does not require the unusual command pipeline that cpio(1) uses.

Most versions of tar(1) do not support backups across the network. The GNU version of tar(1), which FreeBSD utilizes, supports remote devices using the same syntax as rdump(8). To tar(1) to an Exabyte tape drive connected to a Sun called komodo, use: /usr/bin/tar cf komodo:/dev/nrsa8 . 2>&1. For versions without remote device support, you can use a pipeline and rsh(1) to send the data to a remote tape drive. (XXX add an example command)

9.2.3. Cpio

cpio(1) is the original Unix file interchange tape program for magnetic media. cpio(1) has options (among many others) to perform byte-swapping, write a number of different archives format, and pipe the data to other programs. This last feature makes cpio(1) and excellent choice for installation media. cpio(1) does not know how to walk the directory tree and a list of files must be provided through stdin.

cpio(1) does not support backups across the network. You can use a pipeline and rsh(1) to send the data to a remote tape drive. (XXX add an example command)

9.2.4. Pax

pax(1) is IEEE/POSIX's answer to tar(1) and cpio(1). Over the years the various versions of tar(1) and cpio(1) have gotten slightly incompatible. So rather than fight it out to fully standardize them, POSIX created a new archive utility. pax(1) attempts to read and write many of the various cpio(1) and tar(1) formats, plus new formats of its own. Its command set more resembles cpio(1) than tar(1).

9.2.5. Amanda

Amanda (Advanced Maryland Network Disk Archiver) is a client/server backup system, rather than a single program. An Amanda server will backup to a single tape drive any number of computers that have Amanda clients and network communications with the Amanda server. A common problem at locations with a number of large disks is the length of time required to backup to data directly to tape exceeds the amount of time available for the task. Amanda solves this problem. Amanda can use a "holding disk" to backup several filesystems at the same time. Amanda creates "archive sets": a group of tapes used over a period of time to create full backups of all the filesystems listed in Amanda's configuration file. The "archive set" also contains nightly incremental (or differential) backups of all the filesystems. Restoring a damaged filesystem requires the most recent full backup and the incremental backups.

The configuration file provides fine control backups and the network traffic that Amanda generates. Amanda will use any of the above backup programs to write the data to tape. Amanda is available as either a port or a package, it is not installed by default.

9.2.6. Do nothing

``Do nothing'' is not a computer program, but it is the most widely used backup strategy. There are no initial costs. There is no backup schedule to follow. Just say no. If something happens to your data, grin and bear it!

If your time and your data is worth little to nothing, then ``Do nothing'' is the most suitable backup program for your computer. But beware, Unix is a useful tool, you may find that within six months you have a collection of files that are valuable to you.

``Do nothing'' is the correct backup method for /usr/obj and other directory trees that can be exactly recreated by your computer. An example is the files that comprise these handbook pages-they have been generated from SGML input files. Creating backups of these HTML files is not necessary. The SGML source files are backed up regularly.

9.2.7. Which Backup Program is Best?

dump(8) Period. Elizabeth D. Zwicky torture tested all the backup programs discussed here. The clear choice for preserving all your data and all the peculiarities of Unix filesystems is dump(8). Elizabeth created filesystems containing a large variety of unusual conditions (and some not so unusual ones) and tested each program by do a backup and restore of that filesystems. The peculiarities included: files with holes, files with holes and a block of nulls, files with funny characters in their names, unreadable and unwritable files, devices, files that change size during the backup, files that are created/deleted during the backup and more. She presented the results at LISA V in Oct. 1991. See torture-testing Backup and Archive Programs.

9.2.8. Emergency Restore Procedure

9.2.8.1. Before the Disaster

There are only four steps that you need to perform in preparation for any disaster that may occur.

First, print the disklabel from each of your disks (e.g. disklabel da0 | lpr), your filesystem table (/etc/fstab) and all boot messages, two copies of each.

Second, determine that the boot and fixit floppies (boot.flp and fixit.flp) have all your devices. The easiest way to check is to reboot your machine with the boot floppy in the floppy drive and check the boot messages. If all your devices are listed and functional, skip on to step three.

Otherwise, you have to create two custom bootable floppies which has a kernel that can mount your all of your disks and access your tape drive. These floppies must contain: fdisk(8), disklabel(8), newfs(8), mount(8), and whichever backup program you use. These programs must be statically linked. If you use dump(8), the floppy must contain restore(8).

Third, create backup tapes regularly. Any changes that you make after your last backup may be irretrievably lost. Write-protect the backup tapes.

Fourth, test the floppies (either boot.flp and fixit.flp or the two custom bootable floppies you made in step two.) and backup tapes. Make notes of the procedure. Store these notes with the bootable floppy, the printouts and the backup tapes. You will be so distraught when restoring that the notes may prevent you from destroying your backup tapes (How? In place of tar xvf /dev/rsa0, you might accidently type tar cvf /dev/rsa0 and over-write your backup tape).

For an added measure of security, make bootable floppies and two backup tapes each time. Store one of each at a remote location. A remote location is NOT the basement of the same office building. A number of firms in the World Trade Center learned this lesson the hard way. A remote location should be physically separated from your computers and disk drives by a significant distance.

An example script for creating a bootable floppy:


    #!/bin/sh

    #

    # create a restore floppy

    #

    # format the floppy

    #

    PATH=/bin:/sbin:/usr/sbin:/usr/bin

    

    fdformat -q fd0

    if [ $? -ne 0 ]

    then

         echo "Bad floppy, please use a new one"

         exit 1

    fi

    

    # place boot blocks on the floppy

    #

    disklabel -w -B /dev/rfd0c fd1440

    

    #

    # newfs the one and only partition

    #

    newfs -t 2 -u 18 -l 1 -c 40 -i 5120 -m 5 -o space /dev/rfd0a

    

    #

    # mount the new floppy

    #

    mount /dev/fd0a /mnt

    

    #

    # create required directories 

    #

    mkdir /mnt/dev

    mkdir /mnt/bin

    mkdir /mnt/sbin

    mkdir /mnt/etc

    mkdir /mnt/root

    mkdir /mnt/mnt          # for the root partition

    mkdir /mnt/tmp

    mkdir /mnt/var

    

    #

    # populate the directories

    #

    if [ ! -x /sys/compile/MINI/kernel ] 

    then

         cat << EOM

    The MINI kernel does not exist, please create one.

    Here is an example config file:

    #

    # MINI -- A kernel to get FreeBSD on onto a disk.

    #

    machine     "i386"

    cpu     "I486_CPU"

    ident       MINI

    maxusers    5

    

    options     INET            # needed for _tcp _icmpstat _ipstat

                         #            _udpstat _tcpstat _udb

    options     FFS         #Berkeley Fast File System

    options     FAT_CURSOR      #block cursor in syscons or pccons

    options     SCSI_DELAY=15       #Be pessimistic about Joe SCSI device

    options     NCONS=2     #1 virtual consoles

    options     USERCONFIG      #Allow user configuration with -c XXX

    

    config      kernel  root on da0 swap on da0 and da1 dumps on da0

    

    controller  isa0

    controller  pci0

    

    controller  fdc0    at isa? port "IO_FD1" bio irq 6 drq 2 vector fdintr

    disk        fd0 at fdc0 drive 0

    

    controller  ncr0

    

    controller  scbus0

    

    device      sc0 at isa? port "IO_KBD" tty irq 1 vector scintr

    device      npx0    at isa? port "IO_NPX" irq 13 vector npxintr

    

    device      da0

    device      da1

    device      da2

    

    device      sa0

    

    pseudo-device   loop        # required by INET

    pseudo-device   gzip        # Exec gzipped a.out's

    EOM

         exit 1

    fi

    

    cp -f /sys/compile/MINI/kernel /mnt

    

    gzip -c -best /sbin/init > /mnt/sbin/init

    gzip -c -best /sbin/fsck > /mnt/sbin/fsck

    gzip -c -best /sbin/mount > /mnt/sbin/mount

    gzip -c -best /sbin/halt > /mnt/sbin/halt

    gzip -c -best /sbin/restore > /mnt/sbin/restore

    

    gzip -c -best /bin/sh > /mnt/bin/sh

    gzip -c -best /bin/sync > /mnt/bin/sync

    

    cp /root/.profile /mnt/root

    

    cp -f /dev/MAKEDEV /mnt/dev

    chmod 755 /mnt/dev/MAKEDEV

    

    chmod 500 /mnt/sbin/init

    chmod 555 /mnt/sbin/fsck /mnt/sbin/mount /mnt/sbin/halt

    chmod 555 /mnt/bin/sh /mnt/bin/sync

    chmod 6555 /mnt/sbin/restore

    

    #

    # create the devices nodes 

    #

    cd /mnt/dev

    ./MAKEDEV std

    ./MAKEDEV da0

    ./MAKEDEV da1

    ./MAKEDEV da2

    ./MAKEDEV sa0

    ./MAKEDEV pty0

    cd /

    

    #

    # create minimum filesystem table

    #

    cat > /mnt/etc/fstab <<EOM

    /dev/fd0a   /   ufs rw 1 1

    EOM

    

    #

    # create minimum passwd file

    #

    cat > /mnt/etc/passwd <<EOM

    root:*:0:0:Charlie &:/root:/bin/sh

    EOM

    

    cat > /mnt/etc/master.passwd <<EOM

    root::0:0::0:0:Charlie &:/root:/bin/sh

    EOM

    

    chmod 600 /mnt/etc/master.passwd

    chmod 644 /mnt/etc/passwd

    /usr/sbin/pwd_mkdb -d/mnt/etc /mnt/etc/master.passwd

    

    #

    # umount the floppy and inform the user

    #

    /sbin/umount /mnt

    echo "The floppy has been unmounted and is now ready."

9.2.8.2. After the Disaster

The key question is: did your hardware survive? You have been doing regular backups so there is no need to worry about the software.

If the hardware has been damaged. First, replace those parts that have been damaged.

If your hardware is okay, check your floppies. If you are using a custom boot floppy, boot single-user (type -s at the boot: prompt). Skip the following paragraph.

If you are using the boot.flp and fixit.flp floppies, keep reading. Insert the boot.flp floppy in the first floppy drive and boot the computer. The original install menu will be displayed on the screen. Select the Fixit--Repair mode with CDROM or floppy. option. Insert the fixit.flp when prompted. restore and the other programs that you need are located in /mnt2/stand.

Recover each filesystem separately.

Try to mount(8) (e.g. mount /dev/da0a /mnt) the root partition of your first disk. If the disklabel was damaged, use disklabel(8) to re-partition and label the disk to match the label that your printed and saved. Use newfs(8) to re-create the filesystems. Re-mount the root partition of the floppy read-write (mount -u -o rw /mnt). Use your backup program and backup tapes to recover the data for this filesystem (e.g. restore vrf /dev/sa0). Unmount the filesystem (e.g. umount /mnt) Repeat for each filesystem that was damaged.

Once your system is running, backup your data onto new tapes. Whatever caused the crash or data loss may strike again. An another hour spent now, may save you from further distress later.



Banner.Novgorod.Ru