DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Working with disks, tapes, and CD-ROMs

Creating a backup with tar

A tar(C) backup is a special file that contains other files and their associated directory information in linear order. tar was originally created for archiving files to tape, hence the name.

You can specify a list of files to archive by name; and copies of all of the files will be stored in the archive. tar creates the archive by reading the files one at a time, writing a header (containing information about the files) and then writing the contents of the files to the device or tarfile. Consequently, a tarfile is always slightly larger than the total size of the files it contains.

You may find tar useful for archiving infrequently-used files in a directory; create a tarfile containing copies of all the files, remove the originals, then use compress(C) to reduce the size of the tarfile. The result is a convenient, compact package containing the archived material.

To create a tar file on a floppy disk, use the command tar cvn where the c option creates a new backup, overwriting any data already existing on the device, v (verbose) displays each file as it is copied, and n is the number of a device specified in the ``Key'' column of the file /etc/default/tar. To see the list of available device numbers, type tar without arguments, as follows:

   $ tar
   Usage: tar -{txruc}[0-9vfbkelmnpwAFL] [tapefile] [blocksize]
          [tapesize] files ...
           Key     Device            Block   Size(K)    Tape
           0       /dev/rfd048ds9    18      360        No
           1       /dev/rfd148ds9    18      360        No
           2       /dev/rfd096ds15   10      1200       No
           3       /dev/rfd196ds15   10      1200       No
           4       /dev/rfd0135ds9   18      720        No
           5       /dev/rfd1135ds9   18      720        No
           6       /dev/rfd0135ds18  18      1440       No
           7       /dev/rfd1135ds18  18      1440       No
           8       /dev/rct0         20      0          Yes
           9       /dev/rctmini      20      0          Yes
Using this list, you can select the size of floppy disk you want to use. For example, to create a tarfile on a 720KB floppy disk in the second floppy disk drive, containing all files in the directory work, type the following command line:
   $ tar cv5 work
For details of how floppy disk drive names are constructed, see ``Identifying device files''.

To use a device not listed in /etc/default/tar, use the tar f option. This causes the next argument (device) to be the target drive. For example, the command to back up all the files from the current directory and all subdirectories to a 1.2MB floppy in drive 0 is as follows:

   $ tar cvf /dev/rfd096ds15 .
In this example, tar uses a relative pathname, (.), standing for the current working directory, rather than an absolute pathname. This allows you to restore the files to another location. If you give tar absolute pathnames, it will restore files to their original location, creating any intervening directories.

If you want to add files to an archive, rather than overwriting the existing contents, use the r option instead of c; this appends the files to the archive rather than creating a new one. Note that this only works for archives held on disk; you cannot use the r option with tapes.

If you do not specify a device, the tar backup will be created on the default device defined in /etc/default/tar. This default entry is not displayed when you type tar on the command line; list the contents of /etc/default/tar to see something like the following:

   $ cat /etc/default/tar
   .
   .
   .
   # Default device in the absence of a numeric or "-f device" argument
   archive=/dev/rfd0135ds18        18      1440    n
Note that no ``Key'' column is displayed.

If you specify a filename instead of a device name, tar will still create the backup. For example, you could store the files from work in a file called work.tar in the current directory with the following command:

   $ tar cvf work.tar work

Next topic: Listing the files in a tar backup
Previous topic: Using CD-ROMs

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003