Technical article 104340

Restoring the contents of certain directories from a cpio backup.

OpenServer 6.0.0OpenServer 5.0.0OpenServer 5.0.2OpenServer 5.0.4OpenServer 5.0.5OpenServer 5.0.6OpenServer 5.0.7UnixWare 7.0.0UnixWare 7.0.1UnixWare 7.1.0UnixWare 7.1.1UnixWare 7.1.2UnixWare 7.1.3UnixWare 7.1.4Open UNIX 8

Written · Last revised

Problem

How to restore the contents of certain directories from a cpio backup.

Solution

A cpio command to extract directories "foo" and "goo" from a tape
requires the complete pathname of "foo" and "goo", as listed on
the tape.  If the backup is a relative backup, then the files and
subdirectories from the tape are restored into the directory you are
in when issuing the cpio command.  If the backup is an absolute
backup, then "foo/*" and "goo/*" will be restored to the directory
indicated by the absolute pathname on the tape.  Absolute pathnames
can be suppressed when restoring a cpio backup by using a parameter
to strip off the leading slash character.
The next command can be used to verify the backup on the tape and
to find out the directory pathnames to all files on the tape.  Note
that you should replace "/dev/rct0" with a device appropriate to
your system:
# cpio -itv -I/dev/rct0

For example, files in your listing may contain long directory paths.

/dir1/goo/file1
/dir1/dir2/foo/file2
/dir1/dir2/foo/dir3/file3

These are absolute pathnames, ie., they begin with a leading slash.

./dir1/goo/file1
./dir1/dir2/foo/file2
./dir1/dir2/foo/dir3/dir4/file3

These are relative pathnames, i.e., they do not begin with a leading slash, but rather with a file or directory name ("." is the current directory).

To restore "foo", "goo" and all the files and subdirectories of "foo" and "goo", you will need to specify the pathnames leading up to "foo" and "goo" as listed from the tape , followed by a slash (/) and an asterisk (*).

For example, say that the pathnames of "foo" and "goo" as listed from the tape are "./dir1/dir2/foo" and "./dir1/goo" respectively. Since these are relative pathnames (they do not begin with a leading slash), it is first necessary to change to the directory where "foo" and "goo" are to be placed.

Continuing with the example, say you wish to put "goo" and "foo" in /usr/group2/mary, then type the following:

# cd /usr/group2/mary

Then use cpio to restore the "foo" and "goo" directories:

# cpio -icdmuv -I/dev/rct0 './dir1/dir2/foo/*' './dir1/goo/*'

Alternatively, the following syntax may also be used to restore the above directories:

# cpio -icdmuv -I/dev/rct0 ./dir1/dir2/foo/\* ./dir1/goo/\*

If you have an absolute backup (the entries begin with a leading slash), add a -A parameter to the parameter list of the command and search for a pattern that has the leading slash removed:

# cpio -icdmuvA -I/dev/rct0 'dir1/dir2/foo/*' 'dir1/goo/*'
The parameters are very important in getting cpio to restore files
and directories correctly.  Also, blocking and bufsize may need to
be specified for your tape drive.

You can also use "!" to negate certain directories, for example:

# cpio -icdmuvA -I/dev/rct0 !'dir1/dir2*'
would install everything EXCEPT in dir1/dir2.

NOTE: You can only use ! once, eg. !'dir1/dir2/foo/*' !'dir1/goo/*' is not valid.

If in any doubt, use cpio -itv to view the contents first with your parameters or create a smaller archive to disk first to ensure your syntax is correct.

-i  copy in
-c  write header information in character format for portability
-d  create directories as needed
-m  keep original file modification time
-u  copy unconditionally (older file will replace newer one!)
-v  list file names
-t  list files on archive, do not extract any files
-A  suppress absolute pathnames during copy-in
-B  use with character special devices to change default
    blocking from 512 bytes to 5,120 bytes
-Cbufsize  use with character special devices to change default
           bufsize from 512 to one specific to your tape drive

See also

This database contains several other articles on backups.  For
more information, please refer to manual pages for cpio(C).

From the Xinuos technical article database, record 104340. Reproduced with permission. The original is at www.sco.com/ta/104340, which is reachable but blocked from search engines.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.