System Administration Guide, Volume 1

Copying Files to a Tape With pax

This section describes how to copy files with the pax command.

How to Copy Files to a Tape (pax)

  1. Change to the directory that contains the files you want to copy.

  2. Insert a write-enabled tape into the tape drive.

  3. Copy the files to tape with the pax command.


    $ pax -w -f /dev/rmt/0 filename ...

    -w

    Enables the write mode. 

    -f /dev/rmt/0

    Identifies the tape drive. 

    filename ...

    Indicates the files and directories you want to copy. 

  4. Verify the files are copied to tape.


    $ pax -f /dev/rmt/0
    
  5. Remove the tape from the drive and write the names of the files on the tape label.

Example--Copying Files to a Tape (pax)


$ pax -w -f /dev/rmt/0 .
$ pax -f /dev/rmt/0
filea fileb filec

See pax(1) for more information.

How to Copy All Files in a Directory to a Tape (cpio)

  1. Insert a tape that is not write-protected into the tape drive.

  2. Copy files to a tape using the ls and cpio commands.


    $ ls | cpio -oc > /dev/rmt/n
    

    ls

    Provides the cpio command with a list of file names.

    cpio -oc

    Specifies that cpio should operate in copy-out mode (-o) and write header information in ASCII character format (-c). This ensures portability to other vendor's systems.

    > /dev/rmt/n

    Specifies the output file. 

    All files in the directory are copied to the tape in the drive you specify, overwriting any existing files on the tape. The total number of blocks copied is shown.

  3. Verify the files are copied to tape by using the following cpio command.


    $ cpio -civt < /dev/rmt/0
    
  4. Remove the tape from the drive and write the names of the files on the tape label.

Example--Copying All Files in a Directory to a Tape (cpio)

The following example copies all of the files in the directory /export/home/kryten to the tape in tape drive 0.


$ cd /export/home/kryten
$ ls | cpio -oc > /dev/rmt/0
92 blocks
$ cpio -civt < /dev/rmt/0
-rw------t    1 kryten     users        400 Jul 14 09:28 1999, b
drwx--x--x    2 kryten     users          0 Jul 14 09:26 1999, letters
-rw------t    1 kryten     users      10000 Jul 14 09:26 1999, letter1
-rw------t    1 kryten     users      10100 Jul 14 09:26 1999, letter2
-rw------t    1 kryten     users      11100 Jul 14 09:27 1999, letter3
-rw------t    1 kryten     users      12300 Jul 14 09:27 1999, letter4
drwx--x--x    2 kryten     users          0 Jul 14 09:27 1999, memos
-rw------t    1 kryten     users        400 Jul 14 09:28 1999, memosmemoU
-rw------t    1 kryten     users        500 Jul 14 09:28 1999, memosmemoW
-rw------t    1 kryten     users        100 Jul 14 09:27 1999, memosmemoX
-rw------t    1 kryten     users        200 Jul 14 09:28 1999, memosmemoY
-rw------t    1 kryten     users        150 Jul 14 09:28 1999, memosmemoZ
drwx--x--x    2 kryten     users          0 Jul 14 09:24 1999, reports
92 blocks
$

How to List the Files on a Tape (cpio)


Note -

Listing the table of contents takes as long as it does to read the archive file because the cpio command must process the entire archive.


  1. Insert an archive tape into the tape drive.

  2. List the files on the tape using the cpio command.


    $ cpio -civt < /dev/rmt/n
    

    -c

    Specifies that cpio should read files in ASCII character format.

    -i

    Specifies that cpio should operate in copy-in mode (even though it's only listing files at this point).

    -v

    Displays the output in a format similar to the output from the ls -l command.

    -t

    Lists the table of contents for the files on the tape in the tape drive you specify. 

    < /dev/rmt/n

    Specifies the input file of an existing cpio archive.

Example--Listing the Files on a Tape (cpio)

The following example lists the files on the tape in drive 0.


$ cpio -civt < /dev/rmt/0
drwx--x--x    2 kryten    users        0 Jul 14 09:34 1999, answers
-rw------t    1 kryten    users      800 Jul 14 09:36 1999, b
drwx--x--x    2 kryten    users        0 Jul 14 09:32 1999, sc.directives
-rw------t    1 kryten    users   200000 Jul 14 09:35 1999, direct241
drwx--x--x    2 kryten    users        0 Jul 14 09:32 1999, tests
-rw------t    1 kryten    users      800 Jul 14 09:36 1999, test13times
396 blocks

How to Retrieve All Files From a Tape (cpio)

If the archive was created using relative path names, the input files are built as a directory within the current directory when you retrieve the files. If, however, the archive was created with absolute path names, the same absolute paths are used to recreate the file on your system.


Caution - Caution -

Using absolute path names can be dangerous because you might overwrite existing files on your system.


  1. Change to the directory where you want to put the files.

  2. Insert the tape into the tape drive.

  3. Copy all files from the tape to the current directory using the cpio command.


    $ cpio -icvd < /dev/rmt/n
    

    -i

    Reads in the contents of the tape. 

    -c

    Specifies that cpio should read files in ASCII character format.

    -v

    Displays the files being retrieved in a format similar to the output from the ls command.

    -d

    Create directories as needed. 

    < /dev/rmt/n

    Specifies the output file. 

  4. Verify the files are copied by listing the contents of the current directory.


    $ ls -l
    

Example--Retrieving All Files From a Tape (cpio)

The following example retrieves all files from the tape in drive 0.


$ cd /var/tmp
cpio -icvd < /dev/rmt/0
answers 
sc.directives 
tests
8 blocks
$ ls -l

How to Retrieve Specific Files From a Tape (cpio)

  1. Change to the directory where you want to put the files.

  2. Insert the tape into the tape drive.

  3. Retrieve a subset of files from a tape using the cpio command.


    $ cpio -icv "*file" < /dev/rmt/n
    

    -i

    Reads in the contents of the tape. 

    -c

    Specifies that cpio should read headers in ASCII character format.

    -v

    Displays the files as they are retrieved in a format similar to the output from the ls command.

    "*file"

    Specifies that all of the files that match the pattern are copied to the current directory. You can specify multiple patterns, but each must be enclosed in double quotation marks. 

    < /dev/rmt/n

    Specifies the input file. 

  4. Verify the files are copied by listing the contents of the current directory.


    $ ls -l
    

Example--Retrieving Specified Files From a Tape (cpio)

The following example retrieves all files with the suffix chapter from the tape in drive 0.


$ cd /home/smith/Book
$ cpio -icv "*chapter" < /dev/rmt/0
Boot.chapter 
Directory.chapter 
Install.chapter 
Intro.chapter
31 blocks
$ ls -l

See cpio(1) for more information.

How to Copy Files to a Remote Tape Drive (tar and dd)

  1. The following prerequisites must be met to use a remote tape drive:

    • The local hostname (and optionally the username of the user doing the copy) must appear in the remote system's /etc/hosts.equiv file, or the user doing the copy must have his or her home directory accessible on the remote machine, and have the local machine name in $HOME/.rhosts. See hosts.equiv(4) for more information.

    • An entry for the remote system must be in the local system's /etc/inet/hosts file or in the name service hosts file.

  2. To test whether or not you have the appropriate permission to execute a remote command, try the following:


    $ rsh remotehost echo test
    

    If "test" is echoed back to you, you have permission to execute remote commands. If "Permission denied" is echoed, check your setup as described in step 1 above.

  3. To copy files to a remote tape drive, use the tar and dd commands.


    $ tar cf - files | rsh remotehost dd of=/dev/rmt/n obs=blocksize
    

    tar cf

    Creates a tape archive and specifies the tape device. 

    - (Hyphen)

    Represents a place holder for the tape device. 

    files

    Identifies files to be copied. 

    | rsh remotehost

    Pipes the tar command's output to a remote shell to copy the files.

    dd of=/dev/rmt/n

    Represents the output device. 

    obs=blocksize

    Represents the blocking factor. 

  4. Remove the tape from the drive and write the names of the files on the tape label.

Example--Copying Files to a Remote Tape Drive (tar and dd)


# tar cvf - * | rsh mercury dd of=/dev/rmt/0 obs=126b
a answers/ 0 tape blocks
a answers/test129 1 tape blocks
a sc.directives/ 0 tape blocks
a sc.directives/sc.190089 1 tape blocks
a tests/ 0 tape blocks
a tests/test131 1 tape blocks
6+9 records in
0+1 records out

How to Extract Files From a Remote Tape Drive

  1. Change to a temporary directory.


    $ cd /var/tmp
    
  2. To extract files to a remote tape drive, use the tar and dd commands.


    $ rsh remotehost dd if=/dev/rmt/n | tar xvBpf -
    

    rsh remotehost

    Indicates a remote shell that is started to extract the files from the tape device using the dd command.

    dd if=/dev/rmt/n

    Indicates the input device. 

    | tar xvBpf -

    Pipes the output of the dd command to the tar command used to restored the files.

  3. Verify that the files have been extracted.


    $ ls -l /var/tmp
    

Example--Extracting Files From a Remote Tape Drive


$ rsh mercury dd if=/dev/rmt/0 | tar xvBpf -
x answers/, 0 bytes, 0 tape blocks
x answers/test129, 48 bytes, 1 tape blocks
20+0 records in
20+0 records out
x sc.directives/, 0 bytes, 0 tape blocks
x sc.directives/sc.190089, 77 bytes, 1 tape blocks
x tests/, 0 bytes, 0 tape blocks
x tests/test131, 84 bytes, 1 tape blocks
$ ls -l /var/tmp