Россия, Москва, Московский государственный университет им. М. В. Ломоносова, 1989 |
Tapes, backups and floppy disks
Creating a tar archive
Create an archive with the c option. Unlike most UNIX programs, tar does not require a hyphen (-) in front of the options. For example, 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. In this case, it's a disk file.
- /usr/src/sys is the name of the directory to archive. tar archives all files in the directory, including most devices. For historical reasons, tar can't back up devices with minor numbers greater than 65536, and changing the format would make it 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.
You can back up to tape in exactly the same way:
# tar cvf /dev/nsa0 /usr/src/sys
There is a simpler way, how ever: if you don't specify a file name, tar looks for the environment variable TAPE. If it finds it, it interprets it as the name of the tape drive. You can make things 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
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 0 Oct 25 15:07 1997 usr/src/sys/ drwxrwxrwx root/bin 0 Oct 25 15:08 1997 usr/src/sys/CVS/ -rw-rw-rw- root/wheel 9 Sep 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 roo t/bin 0 Oct 27 17:11 1997 usr/src/sys/compile/ drwxrwxrwx root/bin 0 Jul 30 10:52 1997 usr/src/sys/compile/CVS/ (etc)
This example shows the use of the v (verbose) option with t. If you don't use 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't use the v option, tar does not list any file names. If you omit the names of the files to extract, tar extracts the complete archive.
Compressed archives
You can 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
Using floppy disks under FreeBSD
I don't like floppy disks. UNIX doesn't like floppy disks. Probably you don't like floppy disks either, but we occasionally have to live with them.
FreeBSD uses floppy disks for one thing only: for initially booting the system on systems that can't boot from CD-ROM. We've already seen that they're unsuitable for archival data storage and data transfer. For this purpose, FreeBSD uses tapes and CD-ROMs, which are much more reliable, and for the data volumes involved in modern computers, they're cheaper and faster.
So why use floppies? The only good reasons are:
- You have a floppy drive. You may not have a tape drive. Before you go out and buy all those floppies, though, consider that it might be cheaper to buy a tape drive and some tapes instead.
- You need to exchange data with people using Microsoft platforms, or with people who don't have the same kind of tape as you do.
In the following sections, we'll look at how to handle floppies under FreeBSD, with particular regard to coexisting with Microsoft. Here's an over view:
- Always format floppies before using them on your system for the first time, even if they've been formatted before. We'll look at that in the next section.
- Just occasionally, you need to create a UNIX file system on floppy. We'll look at that on page 257.
- When exchanging with Microsoft users, you need to create a Microsoft file system. We'll look at that on page 258.
- When exchanging with other UNIX users, whether FreeBSD or not, use tar or cpio. We'll look at how to do that on page 258.
Formatting a floppy
Even if you buy preformatted floppies, it's a good idea to reformat them. Track alignment can vary significantly between individual floppy drives, and the result can be that your drive doesn't write quite on top of the pre-written tracks. I have seen read failure rates as high as 2% on pre-formatted floppies: in other words, after writing 100 floppies with valuable data, the chances are that two of them have read errors. You can reduce this problem by reformatting the floppy in the drive in which it is to be written, but you can't eliminate it.
On Microsoft platforms, you format floppies with the FORMAT program, which performs two different functions when invoked on floppies: it performs both a low-level format, which rewrites the physical sector information, and then it performs what it calls a high-level format, which writes the information necessary for Microsoft platforms to use it as a file system. UNIX calls the second operation creating a file system. It's not always necessary to have a file system on the diskette-in fact, as we'll see, it can be a disadvantage. In addition, FreeBSD offers different kinds of file system, so it performs the two functions with different programs. In this section, we'll look at fdformat, which performs the low-level format. We'll look at how to create a UFS or Microsoft file system in the next section.
To format a diskette in the first floppy drive, /dev/fd0, you would enter:
$ fdformat /dev/fd0 Format 1440K floppy '/dev/fdC? (y/n): y Processing --------------------------------
Each hyphen character (-) represents two tracks. As the format proceeds, the hyphens change to an F (Format) and then to V (Verify) in turn, so at the end the line reads
Processing VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV done.