.TH backups "" "" "Technical Information"
.PC "Strategies for backing up COHERENT"
.PP
.II backups^strategies
This entry describes how to backup files \(em that is, how to copy one or
more selected files onto floppy disks.
You should do this regularly
to provide yourself with a spare copy of valuable files
should your system suffer a catastrophe.
.PP
The strategy you adopt for backups will vary quite a bit, depending upon
the medium onto which you back up your files:
tapes or floppy disks.
Floppy disks are inexpensive, but their limited capacity means that
you have to plan carefully.
Tapes are simpler to use than floppy disks, but are more expensive.
The following sections describe first the strategies for backing up onto
floppy disks; and then for backing up onto tapes.
.SH "Backing up Onto Floppy Disks"
There are two general strategies for backing up files onto floppy disks:
.IP \(bu 0.3i
Use the command
.B tar
to create archives of files on a floppy disk.
This is fine for archiving a limited set of files on an irregular basis.
.IP \(bu
The other strategy uses the command
.B gnucpio
to implement a system of regular dumps.
This strategy is preferred for systems that daily amass data of importance
for a real-world job, such as running a business or managing a research
project.
.PP
You should always have a procedure of backups for your system.
Which strategy you use depends on how you are using your system.
The following sections describe how to implement each strategy of backups.
Note that \*(CO includes a version of the \*(UN utility
.B dump
for the sake of compatibility with older versions of \*(UN and \*(CO;
however,
.B dump
is obsolete, should not be used, and will not be described here.
.PP
Please note that the following descriptions assume that you are using a
5.25-inch, high-density floppy disks set in drive 0 (drive A).
For a list of available floppy-disk devices, see the Lexicon entry for
.BR "floppy disks" .
.PP
The following describes how to use
.B tar
to back up onto floppy disks.
.PP
The first step is to prepare floppy disks to receive files.
Insert a 5.25-inch floppy disk into drive 0, and then type the following
command:
.DM
	/etc/fdformat -v /dev/rfha0
.DE
.PP
The command
.B fdformat
formats the floppy disk, verifying that no media defects exist.
You must perform this task of formatting a floppy disk
before you use it the first time.
.PP
The next step is to create an archive of the files you wish to back up.
Use the portable archive command
.B tar
to collect a mass of files into an archive on the floppy disks.
For example, to archive all files in directory \fBsource\fR, use the
following command:
.DM
	tar cvf /dev/rfha0 source
.DE
.PP
The options \fBcvf\fR tell \fBtar\fR to create an archive, run in verbose
mode, and write the archive onto the device or into the file
named in the next argument.
\fB/dev/rfha0\fR names the floppy device onto which
you wish to write the archive.
Finally, \fBsource\fR is the directory whose files you wish to back up.
.PP
To perform a listing of the contents of the newly created archive, type
.DM
	tar tvf /dev/rfha0
.DE
.PP
The options \fBtvf\fR tell \fBtar\fR to list the contents
of the archive, run in verbose mode,
and read the archive from the device or file named in the next argument.
.PP
To extract several files from the archive, enter a command of the form
.DM
	tar xvf /dev/rfha0 source/myfile 'source/*.c'
.DE
.PP
The options \fBxvf\fR tell \fBtar\fR to extract or unarchive
the specified files, run in verbose mode,
and read the archive from the device or file named in the next argument.
Note that the second file argument contains a ``wildcard'' character
and thus must be quoted to prevent expansion by the shell.
.PP
For more information on how to use
.BR tar ,
see its entry in the Lexicon.
.PP
The following describes how to back up using
.BR gnucpio .
.PP
The \*(CO utility
.B gnucpio
performs mass dumps and restores of files using a
universally recognized file format.
.PP
In this example, dumps are performed monthly, weekly, and daily.
You should prepare at least three sets of floppy disks for the monthly saves,
giving you three months of full backup.
You will use the floppy disks in rotation, with the oldest always used next.
.PP
Once a month, you should dump the entire system.
.PP
Once a week, you should dump
information in the system that is new or has been changed since the
end of the previous week.
You will need five sets of floppy disks,
because some months have five weekends in them.
.PP
Finally, every day you should save information that has changed that day.
For these dumps, you will need five sets of floppy disks:
one for each working day.
You may need extras in case of weekend work.
.PP
Label each set of disks carefully as
\fImonthly\fR, \fIweekly\fR, or \fIdaily\fR.
Label the daily floppy disks ``Monday'' through ``Friday'',
the weekly floppy disks ``Week 1'' through
``Week 5'', and the monthly floppy disks ``Month 1'' through ``Month 3''.
When you perform the dump, write the date on the label.
.PP
The following gives a step-by-step description of how to use
.B gnucpio
to back up files.
.\"If your system has two floppy-disk drives, we recommend that you use drive 1
.\"(i.e., drive B).
.\"It will allow to restore data should you have to boot a sytem from
.\"the emergency floppy disk that should be in drive A.
The next samples are given with the suggestion that your system has only
one 5.25-inch floppy-disk drive.
.IP 1. 0.3i
Log into the system as the superuser
.BR root .
.IP 2.
If you have not yet done so, use the command
.B fdformat
to format a set of floppy disks, as shown above.
With high-density, 5.25-inch floppy disks, a rule of thumb is to prepare
one floppy disk for each megabyte of data to be dumped.
.IP 3.
If other users are logged into the system, use the command
.B wall
to request that they log off.
For example:
.DM
.II wall
	/etc/wall
	Please log off.
	Time for file dump.
	<ctrl-D>
.DE
.IP 4.
Be sure that all users are logged off the system by typing the command:
.DM
.II who
	who
.DE
.IP
This command names all users who are still on the system.
.IP
If they have not logged off in a few minutes, send another message.
Repeat the process until
.B who
shows no users except yourself.
.IP 5.
When all other users have logged off, execute the command
.B shutdown
as described in its Lexicon entry.
.IP 6.
.II fsck
.II mount.all
Run the script
.B mount.all
to mount all of your file systems.
Then, run the \*(CO command
.B fsck
on each file system to check its integrity.
.IP 7.
If this is the last workday of the month, perform a \fImonthly\fR dump,
to back up the entire system.
Insert the first volume of the correct monthly dump
floppy disk into the floppy drive, after adding today's
date to the label, and type the commands:
.DM
	cd /
	find . -print | gnucpio -ocF /dev/rfha0
.DE
.IP
Option
.B \-F
tells
.B gnucpio
to write everything
to the raw, 2400-block, floppy-disk device
.BR /dev/rfha0 .
.IP
Note that if you want to split your dump across different media
(i.e., write the first volume onto tape and the second onto a floppy disk),
you should not use the option
.BR \-F ;
.B gnucpio
will write its output to the standard output, and you can
use the shell operator `>' to redirect that to the device
.BR /dev/rfha0 .
If you do not use
.BR \-F ,
.B gnucpio
will ask you, after it finishes writing a volume,
for the name of the device into which it should redirect the next volume
of output.
.IP
As more floppies are needed,
.B gnucpio
will ask you to insert them.
Be sure to label each floppy disk with its volume number.
.IP 8.
If this is the last work day of the week, but not the last
workday of the month, perform a \fIweekly\fR dump.
Prepare the correct weekly dump floppy disks, add today's date to the label,
insert the first floppy disk, and type the command:
.DM
	cd /
	find . -newer cpio.weekly -print | gnucpio -ocF /dev/rfha0
	touch cpio.weekly
.DE
.IP
This will dump all files that are younger than file
.BR cpios.weekly .
.IP 9.
If this is neither the last workday of the month nor the last
workday of the week, you will perform a \fIdaily\fR dump.
Prepare the daily dump floppy disk
with today's day of the week, add today's date to the label,
insert the first floppy disk into the drive, and type the command:
.DM
	cd /
	find . -newer cpio.daily -print | gnucpio -ocF /dev/rfha0
	touch cpio.daily
.DE
.IP
This will dump files that are younger than file
.BR cpio.daily .
.IP 10.
.II sync
Type
.B sync
to ensure that all buffers are flushed.
.IP 11.
.II reboot
When you are finished dumping data, type the command
.B /etc/reboot
to return your system to multi-user mode.
.PP
For more information on how to use
.B gnucpio
and
.BR find ,
see their respective entries in the Lexicon.
.PP
If you wish, you can back up only limited portions of your system.
To do so, just name in your
.B find
command the directories you wish to back up.
For example, to back up everything in your home directory and in
.BR /usr/lib ,
use the following command:
.DM
	find $HOME /usr/lib -type f -newer cpio.daily -print | gnucpio -ocF /dev/rfha0
	touch cpio.daily
.DE
.PP
When you determine the backup strategy you wish to use, you should save
the appropriate commands into a script, to ensure that backups are run
correctly every time.
.PP
The following describes how to restore files from floppy disks.
.PP
.II restore^files
.II file^restoring
If you find that a file has been inadvertently destroyed,
you can restore the information to disk from backup floppy disks.
.\".PP
.\"To restore a file from a compressed \fBtar\fR archive, use the following
.\"commands.
.\"First, select the appropriate backup disk, insert it into its drive, and
.\"mount it with the following command:
.\".DM
.\"	/etc/mount /dev/fha0 /f0
.\".DE
.\"Next, use the commands \fBzcat\fR and \fBtar\fR to extract the file you want.
.\"For example, if your archive is called \fBbackup.tar.Z\fR
.\"and the file wish to restore is called \fBmyfile\fR, use the following
.\"command to extract it from its archive:
.\".DM
.\"	zcat /f0/backup.tar.Z | tar xf - myfile
.\".DE
.\".PP
.\"The \fBzcat\fR command reads the compressed archive without requiring
.\"that you uncompress it.
.\"The \fBtar\fR command reads the standard input (as indicated by the hyphen `-')
.\"and extracts \fBmyfile\fR from what it reads.
.\".PP
.\"Once you have extracted your file or files, you can unmount the floppy disk
.\"in the usual way and put it away.
.PP
To restore information from backups created with
.B gnucpio
or
.BR tar ,
you must first determine the date and time
that the file was last known to have been modified.
From this date, determine on which set of disks
the file was last correctly dumped.
Find the set of floppy disks labeled with that date,
and insert into the floppy-disk drive the first one in the set.
For example, if you wish to restore the file
.BR myfile ,
from a
.B gnucpio
archive, use the command:
.DM
	gnucpio -icdvF /dev/rfha0 myfile
.DE
.PP
To retrieve
.B myfile
from a
.B tar
archive, use the command:
.DM
	tar xvf /dev/rfha0 myfile
.DE
.PP
Both of these commands
assume that the disks are high-density, 5.25-inch floppies
in drive 0 (drive A).
See the Lexicon article
.B "floppy disk"
for a table that shows which \*(CO device is associated with which
size and density of disk, and which disk drive.
You may have to insert more than one disk from the set of backups
until you find the one that holds the file you want.
.SH "Backing up Onto Tapes"
The strategy for backing up onto tape resembles that for floppy disks,
with the exception that in many instances the tape medium is larger than
the device being backed up.
This makes it worth your while to back up the entire device every time
you do a back up, rather than perform incremental backups.
The reason for this is simple:
the fewer tapes over which you have spread your backups,
the lower the risk that one will fail.
.PP
To back up an entire partition, do the following:
.IP \fB1.\fR 0.3i
Pop a tape into your tape device.
Make sure the tape is appropriately labeled.
.IP \fB2.\fR
Log in as the superuser
.BR root ,
and type the following command:
.DM
	/etc/shutdown single 0
.DE
.IP
This returns your system to single-user mode immediately.
.IP \fB3.\fR
Use the command
.B gtar
to back up your partition, as follows:
.DM
	gtar -cvzf /dev/\fItape\fP \fIdirectory\fR
.DE
.IP
.I tape
identifies the tape device onto which the backup will be written, and
.I directory
identifies the file system to back up.
For example, tape device
.B /dev/rStp2
is a SCSI tape device that has SCSI identifier 2 and performs
autorewinding.
For a list of recognized tape devices, see the article for
.BR tape .
in the Lexicon.
.IP
Please note two points about
.IR directory .
First, do
.I not 
use the absolute path name when specifying a directory:
that is, use
.BR usr ,
.I not
.BR /usr .
.B gtar
strips the leading `/' in any event, but it's always best to
use relative path names whenever possible.
Second, in single-user mode only the root file system is mounted by
default; therefore,
if the file system you wish to back up
resides on its own partition, you must
mount that file system by hand before you begin to back it up.
.IP
Note that the
.B z
option to the
.B gtar
command tells
.B gtar
to use
.B gzip
to compress the files automatically.
File compression is a good idea:
because fewer bits are being written to the tape, the backup will go
faster; and because less tape is used, the risk of a tape failure
is lessened.
.IP \fB3.\fR
When
.B gtar
has finished writing to the tape, wait until the tape finishes rewinding;
then remove it from its drive and put it in a safe place (i.e., away from
magnets and children).
Then type
.B <ctrl-D>
to return your system to multi-user mode.
.PP
That's all there is to it.
To restore information from the tape, put the tape into the drive and
use the
.B gtar
command to fetch the file you want.
For example, to restore file
.B /v/fwb/myfile.c
from a SCSI tape drive that has SCSI identifier 2, use the following
command:
.DM
	gtar -xvzf /dev/rStp2 "v/fwb/myfile.c"
.DE
.PP
Note that the file will be written into a subdirectory of your current
directory.
For example, if your current directory is
.BR /v/fwb ,
then
.B myfile.c
will be restored into a file with the path name
.BR /v/fwb/v/fwb/myfile.c .
This may be a little inconvenient, but is not nearly as inconvenient as
having to create
.B myfile.c
by hand.
.SH "An Example of Using Floppy Tape"
.II "floppy tape"
.II QIC-40
.II QIC-80
This section gives examples of how to use QIC-40/QIC-80 (``floppy tape'')
to write archives to floppy tape, and read them back.
It uses the commands
.BR tape ,
which manipulates the tape device; and
.BR gtar ,
which writes archives onto the physical tape, and reads them back.
.PP
Suppose you have a directory named
.BR dir1 ,
which contains files you want to backup.
To back up all files in that directory onto a tape, insert a tape
cartridge into the drive, then type:
.DM
	gtar -cvf /dev/ft dir1
.DE
.PP
To verify that the contents of the tape match the original files, run
.B gtar
again in verification (``diff'') mode:
.DM
	gtar -df /dev/ft
.DE
.PP
We strongly urge you to verify tapes after they have been written,
especially with floppy-tape devices.
If a tape fails this test, throw it away and build a new archive;
otherwise, you may receive a nasty surprise when you try to restore a file
from that tape.
Do not be surprised if an otherwise sound tape fails after time:
a tape does wear out after a number of uses.
.PP
To later extract the files from the tape, use
.DM
	gtar -xf /dev/ft
.DE
.PP
To use data compression, the preceding commands can be used with the
addition of
.BR gtar 's
option
.BR \-z ,
as follows:
.DM
	gtar -czvf /dev/ft dir1
	gtar -dzf /dev/ft
	gtar -xzf /dev/ft
.DE
.PP
To backup only selected files to tape, you could do the following:
.DM
	find dir -type f -print | sort > Files
.DE
.PP
then manually edit the file
.B Files
so it contains only the names of the files you want to back up.
Then use the command:
.DM
	gtar -cv -T Files -f /dev/ft
.DE
.PP
The previous examples used
.BR /dev/ft ,
the device node that calls for the
tape to be rewound when the device is closed.
This is convenient if you are putting only one archive onto tape.
To concatenate multiple archives on a single cartridge, use the
no-rewind-on-close device.
For example, suppose you have a second directory,
.BR dir2 ,
and you want to back it up on the same tape, after an archive of
.BR dir1 .
The following commands accomplish this:
.DM
	gtar -cvf /dev/nft dir1
	gtar -cvf /dev/nft dir2
.DE
.PP
After each archive is written, the tape remains positioned at the end
of the archive.
To verify the contents of both archives, do the following:
.DM
	# this command rewinds the tape:
	tape rewind
	# this command displays the contents of the first archive:
	gtar -tvf /dev/nft
	# this command displays the contents of the second archive:
	gtar -tvf /dev/nft
.DE
.PP
If you make a note of the locations of archives as they are written, you
can retrieve them later without having to read the preceding archives.
For example:
.DM
	# rewind the tape:
	tape rewind
	# write "dir1" archive at start of tape:
	gtar -cvf /dev/nft dir1
	# find current position of the tape:
	tape tell
.DE
.PP
The command
.B "tape tell"
returns a string of the form:
.DM
	Tape Is at Byte Offset 102400
.DE
.PP
Continuing:
.DM
	# write "dir2" archive after "dir1":
	gtar -cvf /dev/nft dir2
	# read the current position:
	tape tell
.DE
.PP
The second instance of
.B "tape tell"
returns a string of the form:
.DM
	Tape Is at Byte Offset 235520
.DE
.PP
That is, it shows that the tape has advanced after the second archive was
written onto it.
At this point, the cartridge is removed, then reinserted into the
tape drive at a later date:
.DM
	tape seek 102400
	gtar -tvf /dev/tape
.DE
.PP
The command
.B "tape seek"
moves the tape to the byte position
.BR 102400 ,
i.e., the end of the first archive.
This command assumes that you jotted down the position displayed by the command
.B "tape tell"
executed earlier.
The command
.B gtar
then displays the contents of the second archive.
.SH "See Also"
.Xr "Administering COHERENT," administe
.Xr gnucpio, gnucpio
.Xr gtar, gtar
.Xr tape tape
