Go to main content

Managing File Systems in Oracle® Solaris 11.3

Exit Print View

Updated: October 2017
 
 

Copying Files and File Systems to a Tape Device

You can use the tar, pax, and cpio commands to copy files and file systems to a tape device. You can choose the command based on the amount of flexibility and precision you require for the copy. Because all three commands use the raw device, you do not need to format or create a file system on tapes before you use them. The tape drive and device name that you use depend on the hardware configuration for each system. For more information about tape devices, see Choosing Which Media to Use in Managing Devices in Oracle Solaris 11.3.

Copying Files to a Tape Device Using the tar Command

Ensure that you know the following aspects before you copy files to tape using the tar command:

  • Copying files to a tape with the –c option to the tar command destroys any files already on the tape, at or beyond the current tape position.

  • You can use file name substitution wildcards (? and *) as a part of the file name that you specify when copying files. For example, to copy all documents with .doc extension, type *.doc as the file name argument.

  • You cannot use file name substitution wildcards when you extract files from a tar archive.

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

How to Copy Files to a Tape Device Using the tar Command

  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 the tape device.
    $ tar cvf /dev/rmt/n filenames
    c

    Creates an archive.

    v

    Displays the name of each file as it is archived.

    f /dev/rmt/n

    Indicates that the archive should be written to the specified device or file.

    filenames

    Indicates the files and directories that you want to copy. You can copy multiple files by specifying the file names with spaces.

    The file names that you specify are copied to the tape, overwriting any existing files on the tape.

  4. Remove the tape from the drive. Write the names of the files on the tape label.
  5. Verify that the files are copied to the tape.
    $ tar tvf /dev/rmt/n
Example 19  Copying Files to a Tape Device Using the tar Command

The following example shows how to copy three files to the tape in tape drive 0 using the tar command.

$ cd /export/home/kryten
$ ls reports
reportA reportB reportC
$ tar cvf /dev/rmt/0 reports
a reports/ 0 tape blocks
a reports/reportA 59 tape blocks
a reports/reportB 61 tape blocks
a reports/reportC 63 tape blocks
$ tar tvf /dev/rmt/0

How to List All the Files on a Tape Device Using the tar Command

  1. Insert a tape device into the tape drive.
  2. Display the tape contents.
    $ tar tvf /dev/rmt/n
    –t

    Lists the table of contents for the files on the tape.

    –v

    Provides detailed information about the files on the tape, used with the –t option.

    –f /dev/rmt/n

    Indicates the tape device.

Example 20  Listing the Files on a Tape Device Using the tar Command

The following example shows a listing of files on the tape in drive 0.

$ tar tvf /dev/rmt/0
drwxr-xr-x   0/0        0 Jul 14 13:50 2010 reports/
-r--r--r--   0/0   206663 Jul 14 13:50 2010 reports/reportC
-r--r--r--   0/0   206663 Jul 14 13:50 2010 reports/reportB
-r--r--r--   0/0   206663 Jul 14 13:50 2010 reports/reportA

How to Retrieve Files From a Tape Device Using the tar Command

  1. Change to the directory where you want to save the retrieved files.
  2. Insert the tape into the tape drive.
    $ tar xvf /dev/rmt/n [filenames]
    –x

    Indicates that the files must be extracted from the specified archive file. All files on the tape in the specified drive are copied to the current directory.

    –v

    Displays the name of each file as it is retrieved.

    –f /dev/rmt/n

    Indicates the tape device that contains the archive.

    filenames

    Specifies a file to retrieve. You can retrieve multiple files by specifying the file names with spaces.

  3. Verify that the files are copied.
    $ ls -l
Example 21  Retrieving Files From a Tape Device Using the tar Command

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

$ 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

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 more information, see the tar(1) man page.

Copying Files to a Tape Device Using the pax Command

This section describes how to copy files to a tape device using the pax command.

How to Copy Files to a Tape Device Using the pax Command

  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 the 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. You can copy multiple files by specifying the file names with spaces.

  4. Verify that the files are copied to the tape device.
    $ pax -f /dev/rmt/n
  5. Remove the tape device from the drive. Write the names of the files on the tape label.
Example 22  Copying Files to a Tape Device Using the pax Command

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 a Tape Device Using the cpio Command

This section describes how to copy files to a tape device using the cpio command.

How to Copy All the Files in a Directory to a Tape Device Using the cpio Command

  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 the tape device.
    $ ls | cpio -oc > /dev/rmt/n
    ls

    Provides the cpio command with a list of file names.

    –o

    Specifies that the cpio command should operate in copy-out mode. This option ensures portability to other systems of the vendors.

    –c

    Specifies that the cpio command must write header information in ASCII character format. This option ensures portability to other systems of the vendors.

    > /dev/rmt/n

    Specifies the output file.

    All the 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 displayed in the output.

  4. Verify that the files are copied to the tape device.
    $ cpio -civt < /dev/rmt/n
    –c

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

    –i

    Specifies that the cpio command must 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 23  Copying All the Files in a Directory to a Tape a Device Using the cpio Command

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

$ cd /export/home/kryten
$ ls | cpio -oc > /dev/rmt/0
1280 blocks
$ cpio -civt < /dev/rmt/0
-r--r--r--    1 kryten   staff      206663 Jul 14 13:52 2010, filea
-r--r--r--    1 kryten   staff      206663 Jul 14 13:52 2010, fileb
-r--r--r--    1 kryten   staff      206663 Jul 14 13:52 2010, filec
drwxr-xr-x    2 kryten   staff           0 Jul 14 13:52 2010, letters
drwxr-xr-x    2 kryten   staff           0 Jul 14 13:52 2010, reports
1280 blocks

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

How to List the Files on a Tape Device Using the cpio Command

This procedure shows how to list the files on a tape device using the cpio command.


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 24  Listing the Files on a Tape Device Using the cpio Command

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      206663 Jul 14 13:52 2010, filea
-r--r--r--    1 kryten   staff      206663 Jul 14 13:52 2010, fileb
-r--r--r--    1 kryten   staff      206663 Jul 14 13:52 2010, filec
drwxr-xr-x    2 kryten   staff           0 Jul 14 13:52 2010, letters
drwxr-xr-x    2 kryten   staff           0 Jul 14 13:52 2010, reports
1280 blocks

How to Retrieve All the Files From a Tape Device Using the cpio Command

If the archive is created using relative path names, the input files are built as a directory within the current directory when you retrieve the files. If the archive is created with absolute path names, the same absolute paths are used to recreate 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 save the retrieved files.
  2. Insert the tape into the tape drive.
  3. Extract all the files from the tape device.
    $ cpio -icvd < /dev/rmt/n
    –i

    Extracts files from standard input.

    –c

    Specifies that the cpio command must 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 copy was successful by displaying the contents of the destination directory.
    $ ls -l
Example 25  Retrieving All the Files From a Tape Device Using the cpio Command

The following example shows how to retrieve all the 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 a Specific File From a Tape Device Using the cpio Command

This procedure shows how to retrieve a specific file from a tape device using the cpio command.

  1. Change to the directory where you want to save the retrieved files.
  2. Insert the tape into the tape drive.
  3. Retrieve a subset of files from the tape.
    $ cpio -icv "*file" < /dev/rmt/n
    –i

    Extracts files from standard input.

    –c

    Specifies that the cpio command should read headers 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.

    *file

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

    < /dev/rmt/n

    Specifies the input file.

  4. Verify that the files are copied.
    $ ls -l
Example 26  Retrieving a Specific File From a Tape Device Using the cpio Command

The following example shows how to retrieve all files with the chapter suffix 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

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