UNIX / Linux Tutorial

2.7.2 gzip and compress  |  2.7.3 Putting Them Together  |  2.8 Using Floppies And Making Backups  |  2.8.1 Using Floppies For Backups  |  2.8.2 Backups With A Zip Drive

2.7.2 gzip and compress

Unlike archiving programs for MS-DOS, tar does not automatically compress files as
it archives them. If you are archiving two, 1-megabyte files, the resulting tar file is two
megabytes in size. The gzip command compresses a file (it need not be a tar file). The
command :
                           # gzip -9 backup.tar

compresses backup.tar and leaves you with backup.tar.gz, a compressed version
of the file. The -9 switch tells gzip to use the highest compression factor.
The gunzip command may be used to uncompress a gzipped file. Equivalently, you
may use "gzip -d".

gzip is a relatively new tool in the UNIX community. For many years, the compress
command was used instead. However, because of several factors, including a software
patent dispute against the compress data compression algorithm, and the fact that gzip
is much more efficient, compress is being phased out.

Files that are output by compress end in ".Z." backup.tar.Z is the compressed
version of backup.tar, while backup.tar.gz is the gzipped version
2
.The uncompress command is used to expand a compressed file. It is equivalent to
"compress -d." gunzip knows how to handle compressed files as well.

2.7.3 Putting Them Together

To archive a group of files and compress the result, use the commands :

                 # tar cvf backup.tar /etc

                 # gzip -9 backup.tar

The result is backup.tar.gz. To unpack this file, use the reverse commands :

                # gunzip backup.tar.gz

                # tar xvf backup.tar

Always make sure that you are in the correct directory before unpacking a tar file.
You can use some Linux cleverness to do this on one command line :

               # tar cvf - /etc j gzip -9c > backup.tar.gz

Here, we send the tar file to "-", which stands for tar's standard output. This is 
piped to gzip, which compresses the incoming tar file. The result is saved in backup.tar.gz.
The -c option tells gzip to send its output to standard output, which is redirected to
backup.tar.gz.

A single command to unpack this archive would be :

                # gunzip -c backup.tar.gz j tar xvf -

Again, gunzip uncompresses the contents of backup.tar.gz and sends the resulting
tar file to standard output. This is piped to tar, which reads "-", this time 
referring to tar's standard input.

Note:
For some time, the extension .z (lowercase "z") was used for gzipped files. The 
conventional gzip extension is now .gz..

Happily, the tar command also includes the z option to automatically compress/
uncompress files on the fly, using the gzip compression algorithm.

The command :

               # tar cvfz backup.tar.gz /etc

is equivalent to :

               # tar cvf backup.tar /etc

               # gzip backup.tar

Just as the command :

              # tar xvfz backup.tar.Z

may be used instead of :

             # uncompress backup.tar.Z

             # tar xvf backup.tar

Refer to the tar and gzip manual pages for more information.

2.8 Using Floppies And Making Backups

Floppies are often used as backup media. If you don't have a tape drive connected
to your system, floppy disks can be used (although they are slower and somewhat less
reliable).

As mentioned earlier, floppy diskettes must be formatted with the MS-DOS

FORMAT.COM or the Linux fdformat program. This lays down the sector and track
information that is appropriate to the floppy's capacity.

A few of the device names and formats of floppy disks which are accessible by Linux
are given in Table 2.4.

Devices which begin with fd0 are the first floppy diskette drive, which is named the A:
drive under MS-DOS. The driver file names of second floppy device begin with fd1. Generally,
the Linux kernel can detect the format of a diskette that has already been formatted—
you can simply use /dev/fd0 and let the system detect the format. But when you first
use completely new, unformatted floppy disks, you may need to use the driver specification
if the system can't detect the diskette's type.

A complete list of Linux devices and their device driver names is given in Linux Allocated
Devices, by H. Peter Anvin.

       Floppy device driver         Format
       /dev/fd0d360                 Double density, 360 Kb, 5.25 inch.
       /dev/fd0h1200                High density, 1.2 MB, 5.25 inch.
       /dev/fd0h1440                High density, 1.44 MB, 3.5 inch.

            Table 2.4: Linux floppy disk formats.

You can also use floppies to hold individual file systems and mount the floppy to access
the data on it. See section 2.8.4.

2.8.1 Using Floppies For Backups

The easiest way to make a backup using floppies is with tar. The command :

                   # tar cvfzM /dev/fd0 /

will make a complete backup of your system using the floppy drive /dev / fd0. The"M"
option to tar allows the backup to span multiple volumes; that is, when one floppy is full,
tar will prompt for the next. The command :

                  # tar xvfzM /dev/fd0

restores the complete backup. This method can also be used with a tape drive connected to
your system.

Several other programs exist for making multiple-volume backups; the backflops
program found on tsx-11.mit.edu may come in handy.

Making a complete backup of the system with floppies can be time and resource
consuming. Many system administrators use an incremental backup policy. Every 
month, a complete backup is made, and every week only those files which have 
been modified in the last week are backed up. In this case, if you trash your system 
in the middle of the month, you can simply restore the last full monthly backup, and 
then restore the last weekly backups as needed.

The find command is useful for locating files which were modified after a certain date.
Several scripts for managing incremental backups can be found on sunsite.unc.edu.

2.8.2 Backups With A Zip Drive

Making backups to a Zip drive is similar to making floppy backups, but because Zip
disks commonly have a capacity of 98 Kb, it is feasible to use a single, mounted Zip 
disk for a single backup archive.

Zip drives are available with three different hardware interfaces: a SCSI interface, an
IDE interface and a parallel port PPA interface. Zip drive support is not included as a
pre-compiled Linux option, but it can be specified when building a custom kernel for your
system.

The SCSI and PPA interface Zip drives use the SCSI interface and follow the naming
conventions for other SCSI devices.

Zip disks are commonly pre-formatted with a MS-DOS file system. You can either use
the existing MS-DOS filesystem, which must be supported by your Linux kernel, or use
mke2fs or a similar program to write a Linux file system to the disk.

A Zip disk, when mounted as the first SCSI device, is /dev/sda4 :

               # mount /dev/sda4 /mnt

It is often convenient to provide a separate mount point for Zip file systems; for example,
/zip. The following steps, which must be executed as root, would create the mount
point:

               # mkdir /zip

               # chmod 0755 /zip

Then you can use /zip for mounting the Zip file system.

Writing archives to Zip disks is similar to archiving to floppies. To archive and compress
the /etc directory to a mounted Zip drive, the command used would be:

              # tar zcvf /zip/etc.tgz /etc

This command could be executed from any directory because it specifies absolute path
names. The archive name etc.tgz is necessary if the Zip drive contains a MS-DOS file
system, because any files written to the disk must have names which conform to MS-DOS
8+3 naming conventions; otherwise, the file names will be truncated.

Similarly, extracting this archive requires the commands:

             #cd /

             # tar zxvf /zip/etc.tgz

To create, for example, an ext2 file system on a Zip drive, you would give the command
(for an unmounted Zip disk) :

             # mke2fs /dev/sda4

With a Zip drive mounted in this manner, with an ext2 file system, it is possible to back
up entire file systems with a single command :

            # tar zcvf /zip/local.tar.gz /usr/local

Note that backing up with tar is still preferable in many cases to simply making an
archival copy with the cp -a command, because tar preserves the original files' modification
times.

HOME

1.1 Introduction   1.2.10 Referring To Home Directories   1.3.4  Copying Files

1.6 Exploring The File System   1.8   Wildcards   1.9.3 Pipes   1.10.3 Permissions Dependencies

1.12.4  Stopping And Restarting Jobs   1.13.3 Inserting Text   1.13.9 Including Other Files

1.14.3 Shell Initialization Scripts   System Administration   2.3.1 The /etc/imitate file

2.4 Managing File Systems   2.6 Managing Users  2.6.5 Groups   2.7.2 gzip and compress

2.8.3 Making Backups To Tape Devices   2.9.1 Upgrading The Kernel   

2.9.3 Installing A Device Driver Module

BOOK: LINUX QUICK COMMAND REFERENCE

http://personal.atl.bellsouth.net/~psadler

© copyright KnowledgeWorks, Inc. (2001)