Sun Microsystems Logo
Products & Services
 
Support & Training
 
 

Previous Previous     Contents     Index     Next Next

Example--Retrieving the Files on a Tape (tar)

The following example shows how to retrieve all the files from the tape in drive 0.

$ cd /var/tmp
$ tar xvf /dev/rmt/0
x reports/, 0 bytes, 0 tape blocks
x reports/reportA, 0 bytes, 0 tape blocks
x reports/reportB, 0 bytes, 0 tape blocks
x reports/reportC, 0 bytes, 0 tape blocks
x reports/reportD, 0 bytes, 0 tape blocks
$ ls -l


Note - The names of the files extracted from the tape must exactly match the names of the files that are stored on the archive. If you have any doubts about the names or paths of the files, first list the files on the tape. For instructions on listing the files on the tape, see How to List the Files on a Tape (tar).


Copying Files to a Tape With the pax Command

ProcedureHow 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.

    $ pax -w -f /dev/rmt/n filenames

    -w

    Enables the write mode.

    -f /dev/rmt/n

    Identifies the tape drive.

    filenames

    Indicates the files and directories that you want to copy. Separate multiple files with spaces.

    For more information, see the pax(1) man page.

  4. Verify that the files are copied to tape.

    $ pax -f /dev/rmt/n

  5. Remove the tape from the drive. Write the names of the files on the tape label.

Example--Copying Files to a Tape (pax)

The following example shows how to use the pax command to copy all the files in the current directory.

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

Copying Files to Tape With the cpio Command

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

  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.

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

    ls

    Provides the cpio command with a list of file names.

    cpio -oc

    Specifies that the cpio command should operate in copy-out mode (-o) and write header information in ASCII character format (-c). These options ensure 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 that are copied is shown.

  4. Verify that the files are copied to tape.

    $ cpio -civt < /dev/rmt/n

    -c

    Specifies that the cpio command should read files in ASCII character format.

    -i

    Specifies that the cpio command should operate in copy-in mode, even though the command is only listing files at this point.

    -v

    Displays the output in a format that is 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 that you specify.

    < /dev/rmt/n

    Specifies the input file of an existing cpio archive.

  5. Remove the tape from the drive. Write the names of the files on the tape label.

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

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

$ cd /export/home/kryten
$ ls | cpio -oc > /dev/rmt/0
16 blocks
$ cpio -civt < /dev/rmt/0
-r--r--r--    1 kryten   staff         76 Oct  7 08:17 2003, filea
-r--r--r--    1 kryten   staff         76 Oct  7 08:17 2003, fileb
-r--r--r--    1 kryten   staff         76 Oct  7 08:17 2003, filec
drwxr-xr-x    2 kryten   staff          0 Oct  7 08:17 2003, letters
drwxr-xr-x    2 kryten   staff          0 Oct  7 08:18 2003, reports
16 blocks
$

ProcedureHow to List the Files on a Tape (cpio)


Note - Listing the table of contents on a tape takes a long time 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.

    $ cpio -civt < /dev/rmt/n

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

The following example shows how to list the files on the tape in drive 0.

$ cpio -civt < /dev/rmt/0
-r--r--r--    1 kryten   staff         76 Oct  7 08:17 2003, filea
-r--r--r--    1 kryten   staff         76 Oct  7 08:17 2003, fileb
-r--r--r--    1 kryten   staff         76 Oct  7 08:17 2003, filec
drwxr-xr-x    2 kryten   staff          0 Oct  7 08:17 2003, letters
drwxr-xr-x    2 kryten   staff          0 Oct  7 08:18 2003, reports
16 blocks

ProcedureHow 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 re-create the file on your system.


Caution! Caution - The use of 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. Extract all files from the tape.

    $ cpio -icvd < /dev/rmt/n

    -i

    Extracts files from standard input.

    -c

    Specifies that the cpio command should read files in ASCII character format.

    -v

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

    -d

    Creates directories as needed.

    < /dev/rmt/n

    Specifies the output file.

  4. Verify that the files were copied.

    $ ls -l

Previous Previous     Contents     Index     Next Next
 

Updated: 2004-01-29, 13:14