System backups are important for many reasons: Users of your system may
store data in their home directory that is not saved to any other system;
In the event of a system failure, important system configuration information
can be restored to bring the system back online as quick as possible.
Planning and implementing a backup strategy should begin before your
system is setup. The implementation should begin with the paritioning
schemes of your hard disks. A partition which contains system user files
or administrative configuration files should not exceed the size of the
backup medium you plan to use. This will eliminate the use of multiple
tapes and will allow unattended backup operations. An IT department can
save time and personnel with good planning and preperation.
Files located in the
/bin /sbin /usr/bin /usr/sbin
directories are usually contained within a system installation medium
and never change. There is no reason to backup these directories. Files
located in the
/ /home /var/spool/mail
directories are rather dynamic and should be present in the backup
procedure. The /var directory is very dynamic in nature and should
be a seperate partition to reduce the impact of external fragmentation
on the root partition.
Tape Backup Operations
You need root permission to access the tape device, usually /dev/st0,
/dev/tape, or /dev/ftape.
The mt command is used to control your tape drive.
% mt -f /dev/ftape [retension|rewind|status|erase]
Modules used as drivers for tape devices include:
% insmod paride
% insmod epat
% insmod pt
Using the tar (Tape ARchive) utility:
% tar czvf /dev/npt0 /etc
Ftape HOWTO:
7.1. Writing an archive to a tape
You can use `tar', `dd', `cpio', and `afio'. You will need to use `mt'
to get the full potential of your tapes and the ftape driver. For a
start I'd recommend using `tar', as it can archive lots of directories
and let you pick out separate files from an archive. cpio creates
smaller archives and is more generally more flexible than tar, but is
missing some features like volume labels. `afio' creates backups
where each file is compressed individually and then concatenated.
This will allow you to access the files ``after'' the point of the
error. If you use gzipped tar files, all data after the point of the
error is lost! (to me, this is a pretty good reason for NOT using
compression on backups). The choice of which is most appropriate
depends on the situation and the features and malfeatures of each of
the packages. I recommend taking a look at each package at reviewing
the options that each provides. It's possible that this HOWTO may
provide more detail on this subject at some point in the future.
To make a backup of your kernel source tree using tar, do this
(assuming you have the sources in /usr/src/linux):
# cd /usr/src
# tar cf /dev/ftape linux
This will not compress the files, but gives you a smoother tape run.
If you want the compression (and you've got tar 1.11.2), you just
include the -z flag(*), eg: `tar czf /dev/ftape linux'
7.2. Restoring an archive
OK, let us restore the backup of the kernel source you made in section
``Writing an archive to a tape'' above. To do this you simply say
tar xf /dev/ftape
If you used compression, you will have to say
tar xzf /dev/ftape
When you use compression, gzip will complain about trailing garbage
after the very end of the archive (and this will lead to a `broken
pipe' message). This can be safely ignored.
For the other utilities, please read the man page.
7.3. Testing the archive
tar has an option (-d) for detecting differences between two archives.
To test your backup of the kernel source say
tar df /dev/ftape
If you do not have the man page for tar, you are not lost (yet); tar
has a built-in option list: try `tar --help 2>&1 | less'
7.4. Putting more than one backup on a tape
To put more than one backup on a tape you must have the mt utility.
You will probably have it already, if you got one of the mainline
distributions (eg. Slackware or Debian).
Programs like tar and cpio generate a single Tape ARchive and know
nothing about multiple files or positioning of a tape, it just reads
or writes from/to a device. mt knows everything about moving the tape
back and forth, but nothing about reading the data off the tape. As
you might have guessed, combining tar or cpio with mt does the trick.
By using the nrft[0-3] (nftape) device, you can use `mt' to position
the tape the correct place (`mt -f /dev/nftape fsf 2' means step over
two ``file marks'', i.e. tar files) and then use tar or cpio to read
or write the relevant data.
The most common use of the non-rewinding device is to append another
backup to an existing tape. Here are the specific steps with a little
explanation thrown in for good measure.
· Insert a tape into the drive. On some devices this may cause the
tape to be rewound.
· Issue an End-of-Tape command to the NON-rewinding device.
mt -f /dev/n???? eof
The tape should now be positioned at the End-of-Tape (EOT), which is
actually between to End-of-File (EOF) marks. The tape won't move
unless a program opens the device, closes the rewinding device,
removes the device driver from kernel memory (rmmod) or ejects the
tape. Using `mt eof' may be faster on QIC tapes.
· The next tape operation will start at the End-of-Tape (EOF) mark.
If you perform a write, it will append a new `file'. If you
perform a read it will fail with EOF. The EOT mark on mast tape
formats is actually two consecutive EOF marks. When appending to a
tape the second EOF mark is overwritten with new data, leaving a
normal EOF. If the second EOF is present, it is interpreted as a
logical EOF. Writing the EOF marks is handled by either the device
driver or the hardware when a close() is performed.
· Here's where you write the actual data to the tape.
· Here's the important part. Now rewind the tape. Both ftape and
zftape cache some information that belongs in the header segments
on the tape and update those header segments only when the tape is
rewound. This caching is necessary because rewinding the tape and
updating the header segments takes a conspicious amount of time.
The drawback of this caching is that you will lose information if
you have written to the tape and not rewound the device.
7.5. Appending files to an archive
``Is there a way to extend an archive -- put a file on the tape, then
later, add more to the tape?''
No. The tar documentation will tell you to use `tar -Ar', but it does
not work. This is a limitation of the current ftape driver.
7.6. Mount/unmounting tapes
Since a tape does not have a ``filesystem'' on it, you do not mount /
unmount the tape. To backup, you just insert the tape and run your
`tar' command (or whatever you use to access the tape with).
8. Creating an emergency boot floppy for ftape
This section was written by Claus Tøndering .
Once you are the happy owner of a tape drive and several tapes full of
backups, you will probably ask yourself this question: ``If everything
goes wrong, and I completely lose my hard disk, how do I restore my
files from tape?''
What you need is an emergency floppy disk that contains enough files
to enable you to boot Linux and restore your hard disk from tape.
The first thing you should do is to read ``The Linux Bootdisk HOWTO''
written by Graham Chapman . That document tells
you almost everything you need to know about making an emergency
floppy boot kit. The paragraphs below contain a few extra pieces of
information that will make your life a bit easier when you follow
Graham Chapman's procedures:
· You don't really need /etc/init, /etc/inittab, /etc/getty, and
/etc/rc.d/* on your floppy disk. If Linux doesn't find /etc/init,
it will start /bin/sh on your console, which is fine for restoring
your system. Deleting these files gives you extra space on your
floppy, which you will probably need.
· Find a small version of /bin/sh. They are frequently available on
the boot floppies that come with a Linux distribution. This again
will give you extra space. I'd suggest ash, which is extremely
small (approx 62Kbytes), and yet very bash compatible.
· The /etc/fstab you include on your floppy disk should look
something like this:
/dev/fd0 / minix defaults
none /proc proc defaults
/dev/hda /mnt ext2 defaults
Once you have booted from your floppy, give the command:
mount -av
· Make sure your floppy drive is not mounted when you access the
streamer tape! Otherwise you may get the following error message:
Unable to grab IRQ6 for ftape driver
This means that you MUST load the floppy into a RAMDISK.
This has the unfortunate consequence that the programs needed to
restore the files from the tape can not be located on a separate
floppy disk. You have two options here:
1. You place tar (or cpio or afio or whatever other backup program
you use) on your root floppy disk. (This is where you'll need
all the extra space created in the steps above.)
2. Before you start restoring from tape, copy tar (or cpio or afio
or whatever) to your hard disk and load it from there.
· Apart from your backup program, you will probably need mt on your
root floppy as well.
· Make sure your ftape device (typically /dev/nrft0) is present on
your boot floppy.
· Finally: TRY IT OUT! Of course, I don't recommend that you destroy
your hard disk contents to see if you are able to restore
everything. What I do recommend, however, is that you try booting
from your emergency disks and make sure that you can at least make
a file listing of the contents of your backup tape.
Here's an example of how you can set your rc.local file to use it.
# Install the Floppy Tape Driver
if [ -f /boot/modules/`uname -r`/misc/ftape.o ]; then
echo Installing ftape for Linux `uname -r`
swapout
insmod /boot/modules/`uname -r`/misc/ftape.o
fi
Please note that you won't have this type of problem if you compile
the ftape driver into the kernel.