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

Creating a backup with cpio

The cpio(C) command is a more sophisticated backup tool than tar. It is harder to use, but is capable of copying special files (such as devices and links) consistently, and will accept wildcard characters when listing the files to be archived.

To create a cpio (copy in/out) backup, use the -o (output) mode. You feed a list of files to cpio's standard input; for example, by piping the output from ls to cpio. cpio then copies the files into a single cpio backup file on its standard output, which should be redirected to the appropriate backup device.

For example, to copy all the regular files below your current directory to a 1.2MB disk in the first floppy drive, type the following command line:

   $ find . -type f -depth -print | cpio -ocv > /dev/rfd096ds15
This command uses find(C) to locate all the regular files (-type) in your current directory (.) and its subdirectories (-depth), printing their names through a pipe (|) to cpio. It outputs the names of entries in a directory before the directory itself; that is, it searches ``depth first,'' going to the bottom of the filesystem. cpio then outputs (-o) those files into an archive on /dev/rfd096ds15, a high-density 5¼ inch floppy disk. As it does this, cpio displays their names on the terminal (-v).

The -c option writes the header information in ASCII format. This is a special option that allows cpio archives to be read on any other type of machine equipped with cpio, even if the target machine's architecture differs radically from that of the computer on which the archive was written. (Otherwise, the archive might be nonportable, even though both machines could be running the SCO OpenServer system and cpio.)

The find command above used a relative pathname (.) rather than an absolute pathname. This allows you to restore the files to another location. If you give cpio absolute pathnames, files will be restored to their original location, overwriting any existing data (as with tar).

You may need to make a backup that is larger than the capacity of the disk or tape being used. If this is the case, cpio will stop when it fills the backup medium, and will write a short message prompting you to insert another disk (or tape) and type the name of the device to continue using. If you want to continue backing up on the same device, replace the media and type the device name; if you simply press <Enter>, cpio will terminate.

Pass mode (cpio -p) works like output (cpio -o) mode, except that it copies files to another directory in the filesystem. You can back up files to another floppy disk or to a remote filesystem mounted on your system. You can then restore these files with cpio. For example, to copy all files from your current directory (including all its subdirectories) to a remote filesystem, mounted on the /mnt directory on your system, use the following command:

   $ find . -depth -print | cpio -pvd /mnt/backup6
In this example, backup6 is the name of the backup subdirectory on the /mnt filesystem. This command starts find in the current directory. Rather than following its normal search order (which is to scan all the files in the current directory before entering subdirectories), find with the -depth option dives down as deep as possible in the directory tree, then lists all the files it encounters as it searches. Because this option lists directory paths before the files stored in them, cpio creates the directories before the files.
Next topic: Listing the files in a cpio backup
Previous topic: Extracting files from a tar backup

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005