Tải bản đầy đủ (.pdf) (11 trang)

Chapter-14-Tapes backups and floppy disks

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (116.09 KB, 11 trang )

2Apr il 2003, 17:00:47 The Complete FreeBSD (tapes.mm), page 251
14
Tapes, backups and
floppydisks
In this chapter:
• Backing up your data
• Using floppydisks
under FreeBSD
In this chapter:
• Backing up your data
• Using floppydisks
under FreeBSD
In Chapter 11 we looked at hard disks. In this chapter,we’ll consider howtoguard
against data loss, and howtotransfer data from one location to another.These are
functions that UNIX traditionally performs with tapes, and we’ll look at them in the next
sections. Because FreeBSD runs on PCs, however, you can’tcompletely escape floppy
disks, though it would be an excellent idea. We’lllook at floppies on page 256.
Backing up your data
No matter howreliable your system, you are nevercompletely protected against loss of
data. The most common reasons are hardware failure and human error.Bycomparison,
it’s very seldom that a software error causes data loss, but this, too, can happen.
UNIX talks about archives,which are copies of disk data in a form suitable for writing on
aserial medium such as tape. Youcan, however, write them to disk files as well, and
that’swhat people do when theywant to move a source tree from one system to another.
You’ll also hear the term tarball for an archive made by the tar program, which we
discuss below.
tapes.mm,v v4.10 (2003/04/02 06:47:36) 251
Backing up your data 252
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 252
What backup medium?
Traditionally,PCs use floppydisks as a removable storage medium. We’lllook at


floppies below, but you can sum the section up in one statement: don’tuse floppydisks.
Floppydisks are particularly unsuited as a backup medium for modern computers.
Consider evena minimal system with a 2 GB hard disk. Storing 2 GB of data on floppies
requires about 1,500 floppies, which, at $0.30 each, would cost you $450. Copying the
data to a floppytakes about 50 seconds per floppy, sothe rawbackup time would be
about 21 hours, plus the time it takes you to change the floppies, which could easily take
another three or more hours. During this time you have tosit by the computer playing
disk jockey,atotal of three days’ work during which you could hardly do anything else.
When you try to read in the data again, there’savirtual certainty that one of the floppies
has a data error,especially if you read them with a different drive.
By contrast, a single DDS or Exabyte cassette stores several gigabytes and costs about
$6. The backup time for 2 GB is about 90 minutes, and the operation can be performed
completely unattended.
Anumber of cheaper tape drivesare also available, such as Travantapes. FreeBSD
supports them, but for one reason or another,theyare not popular.FreeBSD once used to
have support for ‘‘floppytape,’’ run offafloppycontroller,but these tapes were very
unreliable, and theyare no longer supported.
Youcan also use writeable ‘‘CD-ROMs’’(CD-Rs) for backup purposes. By modern
standards, the media are small (up to 700 MB), but theyhav e the advantage of being
readily accessible on other systems. We looked at CD-Rs in Chapter 13.
Tape devices
FreeBSD tape devices have names like /dev/nsa0 (see page 196). Each letter has a
significance:
• n means non-rewinding.When the process that accesses the tape closes it, the tape
remains at the same position. This is inconvenient if you want to remove the tape
(before which you should rewind it), but it’sthe only way if you want to handle
multiple archivesonthe tape. The name of the corresponding re wind device has no n
(for example, the rewind device corresponding to /dev/nsa0 is /dev/sa0). A rewind
device rewinds the tape when it is closed.
Older releases of FreeBSD used the names /dev/nrsa0 and /dev/rsa0. r stands for raw,in

other words a character device. Since the removalofblock devices, this letter is superfluous,
butyou might see it occasionally in older documents.
• sa stands for serial access,and is always SCSI. Youcan also get ATAPI tape drives,
which are called /dev/ast0 and /dev/nast0,and the older QIC-02 interface tapes are
called /dev/wst0 and /dev/nwst0.
• 0 is the unit number.Ifyou have more than one tape, the next will be called
/dev/nsa1,and so on.
tapes.mm,v v4.10 (2003/04/02 06:47:36)
253 Chapter 14: Tapes,backups and floppydisks
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 253
Backup software
FreeBSD does not require special ‘‘backup software.’’ The base operating system
supplies all the programs you need. The tape driverispart of the kernel, and the system
includes a number of backup programs. The most popular are:
• tar,the tape archiver,has been around longer than anybody can remember.Itis
particularly useful for data exchange, since everybody has it. There are evenversions
of tar for Microsoft platforms. It’salso an adequate backup program.
• cpio is an alternative backup program. About its only advantage over tar is that it
can read cpio format archives.
• pax is another alternative backup program. It has the advantage that it can also read
and write tar and cpio archives.
• dump is geared more towards backups than towards archiving. It can maintain
multiple levels of backup, each of which backs up only those files that have changed
since the last backup of the next higher (numerically lower) level. It is less suited
towards data exchange because its formats are very specific to BSD. Even older
releases of FreeBSD cannot read dumps created under FreeBSD Release 5.
• amanda,inthe Ports Collection, is another popular backup program.
Backup strategies are frequently the subject of religious wars. I personally find that tar
does everything I want, but you’ll find plenty of people who recommend dump or
amanda instead. In the following section, we’ll look at the basics of using tar.See the

man page dump(8) for more information on dump.
tar
tar,the tape archiver,performs the following functions:
• Creating an archive,which can be a serial device such as a tape, or a disk file, from
the contents of a number of directories.
• Extracting files from an archive.
• Listing the contents of an archive.
tar does not compress the data. The resulting archive isslightly larger than the sum of
the files that it contains, since it also contains a certain amount of header information.
Youcan, however, use the gzip program to compress a tar archive,and tar invokesitfor
you automatically with the -z option. The size of the resultant archivesdepends strongly
on the data you put in them. JPEG images, for example, hardly compress at all, while
text compresses quite well and can be as high as 90% smaller than the constituent files.
tapes.mm,v v4.10 (2003/04/02 06:47:36)
Backing up your data 254
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 254
Creating a tar archive
Create an archive with the c option. Unlikemost UNIX programs,
tar does not require a hyphen (-)infront of the options. Forexample, to save your
complete kernel source tree, you could write:
# tar cvf source-archive.tar /usr/src/sys
tar: Removing leading / from absolute path names in the archive.
usr/src/sys/
usr/src/sys/CVS/
usr/src/sys/CVS/Root
usr/src/sys/CVS/Repository
usr/src/sys/CVS/Entries
usr/src/sys/compile/
usr/src/sys/compile/CVS/
(etc)

The parameters have the following meaning:
• cvf are the options. c stands for create an archive, v specifies verbose operation (in
this case, this causes tar to produce the list of files being archived), and f specifies
that the next parameter is the name of the archive file.
• source-archive.tar is the name of the archive.Inthis case, it’sadisk file.
• /usr/src/sys is the name of the directory to archive. tar archivesall files in the
directory,including most devices. For historical reasons, tar can’tback up devices
with minor numbers greater than 65536, and changing the format would makeit
incompatible with other systems.
The message on the first line (Removing leading / ...)indicates that, although the
directory name was specified as /usr/src/sys, tar treats it as usr/src/sys.This makes
it possible to restore the files into another directory at a later time.
Youcan back up to tape in exactly the same way:
# tar cvf /dev/nsa0 /usr/src/sys
There is a simpler way,howev er: if you don’tspecify a file name, tar looks for the
environment variable TAPE.Ifitfinds it, it interprets it as the name of the tape drive.
Youcan makethings a lot easier by setting the following line in the configuration file for
your shell ( .profile for sh, .bashrc for bash, .login for csh and tcsh):
TAPE=/dev/nsa0 export TAPE for sh and bash
setenv TAPE /dev/nsa0 for csh and tcsh
After this, the previous example simplifies to:
# tar cv /usr/src/sys
tapes.mm,v v4.10 (2003/04/02 06:47:36)
255 Chapter 14: Tapes,backups and floppydisks
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 255
Listing an archive
To list an archive,use the option t:
# tar t from tape
usr/src/sys/
usr/src/sys/CVS/

usr/src/sys/CVS/Root
usr/src/sys/CVS/Repository
usr/src/sys/CVS/Entries
usr/src/sys/compile/
usr/src/sys/compile/CVS/
usr/src/sys/compile/CVS/Root
(etc)
# tar tvf source-archive.tar from disk
drwxrwxrwx root/bin 0Oct 25 15:07 1997 usr/src/sys/
drwxrwxrwx root/bin 0Oct 25 15:08 1997 usr/src/sys/CVS/
-rw-rw-rw- root/wheel 9Sep 30 23:13 1996 usr/src/sys/CVS/Root
-rw-rw-rw- root/wheel 17 Sep 30 23:13 1996 usr/src/sys/CVS/Repository
-rw-rw-rw- root/bin 346 Oct 25 15:08 1997 usr/src/sys/CVS/Entries
drwxrwxrwx root/bin 0Oct 27 17:11 1997 usr/src/sys/compile/
drwxrwxrwx root/bin 0Jul 30 10:52 1997 usr/src/sys/compile/CVS/
(etc)
This example shows the use of the v (verbose)option with t.Ifyou don’tuse it, tar
displays only the names of the files (first example, from tape). If you do use it, tar also
displays the permissions, ownerships, sizes and last modification date in a form
reminiscent of ls -l (second example, which is from the disk file source-archive.tar).
Extracting files
To extract a file from the archive,use the x option:
# tar xv usr/src/sys/Makefile from tape
usr/src/sys/Makefile confirms that the file was extracted
As with the c option, if you don’tuse the v option, tar does not list anyfile names. If
you omit the names of the files to extract, tar extracts the complete archive.
Compressed archives
Youcan combine gzip with tar by specifying the z option. For example, to create the
archive source-archive.tar.gz in compressed format, write:
# tar czf source-archive.tar.gz /usr/src/sys

You must specify the z option when listing or extracting compressed archives, and you
must not do so when listing or extracting non-compressed archives. Otherwise you get
messages like:
# tar tzvf source-archive.tar
gzip: stdin: not in gzip format
tar: child returned status 1
# tar tvf source-archive.tar.gz
tar: only read 2302 bytes from archive source-archive.tar.gz
tapes.mm,v v4.10 (2003/04/02 06:47:36)

×