File System Administration
  Rechercher uniquement dans ce livre
Télécharger cet ouvrage au format PDF

Copying UFS Files and File Systems

4

This chapter contains these sections:
Copying Complete File Systemspage 58
Copying Files and File Systems to Tapepage 65
Copying Files and File Systems to Diskettepage 72
Copying Files with a Different Header Formatpage 76
Retrieving Files Created With the bar Commandpage 77

Commands for Copying File Systems

When you need to back up and restore complete file systems, use the ufsdump and ufsrestore commands described in Part 2 -- "Backup and Restore." When you want to copy or move individual files, portions of file systems, or complete file systems, you can use the procedures described in this chapter as an alternative to ufsdump and ufsrestore. Table 4-1 shows the tasks described in this chapter and the commands that you can use for each task.
Table 4-1
TaskCommands
Copying complete file systemslabelit
volcopy
dd
cpio
Copying files or file systems to tape or diskettetar
cpio
Copying files between systems running different SunOS release
levels
tar
cpio
Copying file archives with different header formatscpio -H format
Copying files to a group of systemsrdist

Copying Complete File Systems

You can copy complete file systems in three ways:
These sections describe the advantages and disadvantages of each method and provide examples of how to use the commands.

Using the labelit and volcopy Commands

The volcopy command makes a literal (block) copy or image of a complete UFS file system on another file system or to a tape. Use this command to make a fast copy of a file system. This kind of image is a literal "snapshot" of the file system.

Note - Making a volcopy image can take quite a bit of time (sometimes hours) because the volcopy command does not write efficiently to streaming tape cartridges.

You must restore the complete volcopy image; you cannot restore only a part of the image. The volcopy command checks the file system label you create using the labelit(1M) command (explained in "Assigning Labels to UFS File Systems" on page 59) and guarantees that the correct volume is mounted. Use the volcopy command to extract a volume that was created with the volcopy command.

Note - volcopy cannot be used to copy file systems from one tape to another.

Assigning Labels to UFS File Systems

You can use the labelit command to write a file system name and a volume name of up to six characters to the superblock of each UFS file system. These file system and volume names can be used as an alternative to specifying the raw character device name as an argument to the volcopy command.

Note - The file system volume name written to the superblock by the labelit command is completely separate from the slice label in the VTOC (volume table of contents) of a file system.

The volume label can be very useful in matching volumes stored on disk packs, diskettes, or tape.
· How to Find the File System and Volume Name
  1. Become superuser.

  2. Type labelit /dev/rdsk/cntndnsn and press Return. The file system name and the volume name are displayed. If no volume name is assigned, the fields are blank.

In this example, no volume name is assigned:

  mars% su  
  Password:  
  # labelit /dev/rdsk/c0t3d0s7  
  fsname:  
  volume:  
  #  

· How to Assign a File System and Volume Name
  1. Become superuser.

  2. Type labelit -F ufs /dev/rdsk/cntndnsn fs-name volume-name and press Return.

    The file system name and the volume name of up to six characters are assigned and displayed.

In this example, the file system name home1 and the volume name vol1 are assigned:

  mars% su  
  Password:  
  # labelit -F ufs /dev/rdsk/c0t030s7 home1 vol1  
  fsname: home1  
  volume: vol1  
  #  

See the labelit(1M) manual page for more information.
· How to Copy File Systems With volcopy

Note - It is just as important for file systems to be quiescent when using the volcopy command as it is when doing backups. See Chapter 3, "Mounting and Unmounting File Systems," for information about unmounting file systems.

  1. Become superuser.

  2. Unmount the file system.

  3. Type volcopy -F ufs fs-name source-device volume-name1 destination-device volume-name2 and press Return.

  4. If you have assigned new labels or changed old ones, you will be asked to confirm that the new information is correct.

  5. Press Return to confirm that you want to copy the volume from the slice to the device you specified.

Example: How to Copy File Systems With volcopy First, use labelit to create a file system name and volume name for the file system:

  # labelit -F ufs /dev/dsk/c0t3d0s7 home1 vol1  
  fsname: home1  
  volume: vol1  
  #  

Next, copy an image of the file system to a tape device, giving it a new volume name, tape1:
Code Example 4-1 Copying File Systems with volcopy

  mars% su  
  Password:  
  mars# cd /  
  mars# umount /dev/dsk/c0t3d0s7  
  mars# volcopy -F ufs home1 /dev/rdsk/c0t3d0s7 vol1 \ /dev/rmt/0  
  tape1  

Code Example 4-1 Copying File Systems with volcopy (Continued)

  arg. (vol1) doesn't agree with from vol.(vol1)  
  Type 'y' to override:        y  
  /dev/rmt/0 less than 48 hours older than /dev/rdsk/c0t3d0s7  
  To filesystem dated:  Thu Mar 12 14:34:48 1992  
  Type 'y' to override:        y  
  arg.(tape1) doesn't agree with to vol.(      )  
  Type 'y' to override:        y  
  warning! from fs(home1) differs from to fs(      )  
  Type 'y' to override:        y  
  From: /dev/rdsk/c0t3d0s7, to: /dev/rmt/0? (DEL if wrong)  
  mars#  

This example shows how volcopy performs a check between the source device and the destination device using the file system name and the volume name. The source volume has no existing label, so you specify its volume and file system name as empty strings. The tape already contained a volcopy image.

  # volcopy -F ufs "" /dev/rdsk/c0t3d0s0 "" /dev/rmt/0l tape1  
  /dev/rmt/0l less than 48 hours older than /dev/rdsk/c0t3d0s0  
  To filesystem dated: Sat Jan 4 14:42:25 1992  
  Type 'y' to override: y  
  arg.(tape1) doesn't agree with to vol.( )  
  Type 'y' to override: y  
  warning! from fs() differs from to fs( )  
  Type 'y' to override: y  
  From: /dev/rdsk/c0t3d0s0, to: /dev/rmt/0l? (DEL if wrong) y  

See the volcopy_ufs(1M) manual page for more information.

Using the dd Command

The dd command makes a literal (block) copy of a complete UFS file system to another file system or to a tape. By default, the dd command copies its standard input to its standard output, so you can copy a file with this command:

  dd < in-file > out-file  


Note - The dd command is not recommended for use with variable-length tape drives.

You can specify a device name in place of the standard input or the standard output or both. In this example, contents of the diskette are copied to a file in the /tmp directory:

  $ dd < /floppy/floppy0 > /tmp/output.file  
  2400+0 records in  
  2400+0 records out  
  $  

The dd command reports on the number of blocks it reads and writes. The number after the + is a count of the partial blocks that were copied.
The dd command syntax is different from most other commands. Options are specified as keyword=value pairs, where keyword is the option you want to set and value is the argument for that option. For example, you can replace the standard input and output with this syntax:
dd if=input-file of=output-file
For example, to use the keyword=value pairs instead of the redirect symbols in the previous example, you would type:

  $ dd if=/floppy/floppy0 of=/tmp/output.file  

See the dd(1M) manual page for more information.

Using the cpio Command

You can use the cpio (copy in and out) command to copy individual files, groups of files, or complete file systems. This section describes how to use the cpio command to copy complete file systems.
The cpio command is an archiving program that takes a list of files and copies them into a single, large output file. It inserts headers between the individual files to facilitate recovery. You can use the cpio command to copy complete file systems to another slice, another system, or to a media device such as tape or diskette.
Because the cpio command recognizes end-of-media and prompts you to insert another volume, it is the most effective command (other than ufsdump) to use to create archives that require multiple tapes or diskettes.
You frequently use commands like ls and find to list and select the files you want to copy and then pipe the output to the cpio command.
· How to Copy Directory Trees Between File Systems
  1. Become superuser.

  2. Type cd /filesystem1 and press Return.

  3. Type find . -print -depth | cpio -pdm /filesystem2 and press Return.

    The files from the directory name you specify are copied and symbolic links are preserved. The . argument to find copies the current working directory, the -print option prints the file names, and the -depth option descends the directory hierarchy and prints file names on the way back up, which allows the -m option to cpio to set the correct modification times on directories. The -p option to cpio creates a list of files. The d option creates directories as needed.

  4. To verify that the copy was successful, type cd /filesystem2;ls and press Return.

  5. If appropriate, to remove the source directory tree, type

    rm -rf /filesystem1 and press Return.

See the cpio(1) manual page for more information.

Copying Files and File Systems to Tape

tar and cpio are commands that can be used to copy files and file systems to tape. The command you choose depends on how much flexibility and precision you require for the copy.
Use tar to copy files and directory subtrees to a single tape. Note that the SunOS 5.x tar command can archive special files (block and character devices, fifos) but the SunOS 4.x tar command cannot extract them. The cpio command provides better portability.
Use cpio to copy arbitrary sets of files, special files, or file systems that require multiple tape volumes or when you want to copy files from SunOS 5.x systems to SunOS 4.x systems. The cpio command packs data onto tape more efficiently than tar and skips over any bad spots in a tape when restoring. The cpio command also provides options for writing files with different header formats (tar, ustar, crc, odc, bar) for portability between systems of different types.
Because tar and cpio use the raw device, you do not need to format or make a file system on tapes before you use them. The tape drive and device name you use depend on the hardware and configuration for each system. See "Choosing Which Media to Use" on page 102 for more information about tape drives and device names.
The information is divided into these sections:

Useful Commands for Streaming Tape Cartridges

This section contains a few commands for use with streaming tape cartridges.
· How to Retension a Magnetic Tape Cartridge
If errors occur when reading a tape, retension the tape, clean the tape drive, and then try again.
* Type mt -f /dev/rmt/n retension and press Return. The tape in the specified tape drive is retensioned.
In this example, the tape in drive /dev/rmt/1 is retensioned:

  venus% mt -f /dev/rmt/1 retension  
  venus%  


Note - The retension option is not recommended for non-QIC tape drives.

· How to Rewind a Magnetic Tape Cartridge
* Type mt -f /dev/rmt/n rewind and press Return. The tape in the specified tape drive is rewound.
In this example, the tape in drive /dev/rmt/1 is rewound:

  venus% mt -f /dev/rmt/1 rewind  
  venus%  

· How to Show the Status of a Magnetic Tape Drive
* Type mt -f /dev/rmt/n status and press Return. Status for the tape drive you specify is displayed.
In this example, there is no tape in drive /dev/rmt/1:

  venus% mt -f /dev/rmt/1 status  
  /dev/rmt/1: no tape loaded or drive offline  
  venus%  

In this example, status is shown for the tape in drive /dev/rmt/1:

  venus% mt -f /dev/rmt/1 status  
  Archive QIC-150 tape drive:  
     sense key(0x6)= unit attention   residual= 0   retries= 0  
     file no= 0   block no= 0  
  venus%  

Using the tar Command

· How to Copy Files to a Tape (tar)
  1. Change to the directory that contains the files you want to copy.

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


CAUTION Caution - Copying files to a tape using the c option to tar destroys any files already on the tape. If you want to preserve the files already on the tape, use the r option described in "How to Append Files to a Tape (tar)" on page 68.

  1. Type tar cvf /dev/rmt/n filename filename filename ... and press Return. The c option indicates that you want to create an archive. The v option displays the name of each file as it is archived. The f option indicates that the archive should be written to the specified device or file. The file names you specify are copied to the tape, overwriting any existing files on the tape.


Note - You can use metacharacters (? and *) as part of the file names you specify. For example, to copy all documents with a .doc suffix, type *.doc as the file name argument.

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

In this example, two files are copied to a tape in tape drive 0:

  venus% cd /home/smith  
  venus% ls evaluation*  
  evaluation.doc   evaluation.doc.backup  
  venus% tar cvf /dev/rmt/0 evaluation*  
  a evaluation.doc 86 blocks  
  a evaluation.doc.backup 84 blocks  
  venus%  

· How to List the Files on a Tape (tar)
  1. Insert a tape into the tape drive.

  1. Type tar tvf /dev/rmt/n and press Return. The t option lists the table of contents for the files on the tape in the tape drive you specify.

In this example, the table of contents for the tape in drive 0 contains two files:

  venus% tar tvf /dev/rmt/0  
  rw-rw-rw-6693/10  44032 Apr 23 14:54 1994 evaluation.doc  
  rw-rw-rw-6693/10  43008 Apr 23 14:47 1994 evaluation.doc.backup  
  venus%  

· How to Append Files to a Tape (tar)
  1. Change to the directory that contains the files you want to copy.

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

  3. Type tar rvf /dev/rmt/n filename filename filename ... and press Return. The r option indicates that the files should be appended to an existing archive. The specified files are appended to the files already on the tape.


Note - You can use metacharacters (? and *) as part of the file names you specify. For example, to copy all documents with a .doc suffix, type *.doc as the file name argument.

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

In this example, one file is appended to the files already on the tape in drive 0:

  venus% cd /home/smith  
  venus% tar rvf /dev/rmt/0 junk  
  a junk 1 blocks  
  venus% tar tvf /dev/rmt/0  
  rw-rw-rw-6693/10  44032 Apr 23 14:54 1994 evaluation.doc  
  rw-rw-rw-6693/10  43008 Apr 23 14:47 1994 evaluation.doc.backup  
  rw-rw-rw-6693/10     18 Dec 10 11:36 1993 junk  
  venus%  

· How to Retrieve Files From a Tape (tar)
  1. Change to the directory where you want to put the files.

  2. Insert the tape into the tape drive.

  3. Type tar xvf /dev/rmt/n and press Return. The x option indicates that files should be extracted from the specified archive file. All of the files on the tape in the specified drive are copied to the current directory.

In this example, all files are copied from the tape in drive 0:

  venus% cd /home/smith/Evaluations  
  venus% tar xvf /dev/rmt/0 evaluation*  
  x evaluation.doc, 44032 bytes, 86 tape blocks  
  x evaluation.doc.backup, 43008 bytes, 84 tape blocks  
  venus%  

To retrieve individual files from a tape:
* Type tar xvf /dev/rmt/n filename filename filename ... and press Return. The file names you specify are extracted from the tape and placed in the current working directory.

Note - The names of the files extracted from the tape exactly match the names of the files stored on the archive. If you have any doubts about the names or paths of the files, first list the files on the tape. See "How to List the Files on a Tape (tar)" on page 67 for instructions.

See the tar(1) manual page for more information.

Using the cpio Command

The cpio command, used to create an archive, takes a list of files or path names from standard input and writes to standard output. The output is almost always redirected to a file or to a device.
· 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. Type ls | cpio -oc > /dev/rmt/n and press Return. All of 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 copied is displayed.

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

In this example, all of the files in the directory /home/smith/TOI are copied to the tape in tape drive 0:

  venus% cd /home/smith/TOI  
  venus% ls | cpio -oc > /dev/rmt/0  
  31 blocks  
  venus%  

· 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 a tape into the tape drive.

  2. Type cpio -civt < /dev/rmt/n and press Return. The i option reads in the contents of the tape. The v option displays the output in a format similar to the output from the ls -l command. The t option lists the table of contents for the files on the tape in the tape drive you specify.

In this example, the table of contents for the tape in drive 0 contains four files:

  venus% cpio -civt < /dev/rmt/0  
  100666 smith   3895  Feb 24 15:13:02 1992  Boot.chapter  
  100666 smith   3895  Feb 24 15:13:23 1992  Directory.chapter  
  100666 smith   6491  Feb 24 15:13:52 1992  Install.chapter  


  100666 smith   1299  Feb 24 15:14:00 1992  Intro.chapter  
  31 blocks  
  venus%  

· 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. If, however, the archive was created with absolute path names, the same absolute paths are used to re-create the file.

CAUTION Caution - Using absolute path names can be dangerous because you will overwrite the original files.

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

  2. Insert the tape into the tape drive.

  3. Type cpio -icv < /dev/rmt/n and press Return. All of the files on the tape in the drive you specify are copied to the current directory.

In this example, all files are copied from the tape in drive 0:

  venus% cpio -icv < /dev/rmt/0  
  Boot.chapter  
  Directory.chapter  
  Install.chapter  
  Intro.chapter  
  31 blocks  
  venus%  

· How to Retrieve a Subset of Files From a Tape (cpio)
You can reload a subset of the files from the archive by specifying a pattern to match using shell wild card characters enclosed in quotes after the options.
  1. Change to the directory where you want to put the files.

  1. Insert the tape into the tape drive.

  2. Type cpio -icv "*file" < /dev/rmt/n and press Return. 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.

In this example, all files that end in the suffix chapter are copied from the tape in drive 0:

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

See the cpio(1) manual page for more information.

Copying Files and File Systems to Diskette

Before you can copy files or file systems to diskette, you must format the diskette. See the Administration Supplement for Solaris Platforms for information on how to format a diskette. Use the tar command to copy UFS files to a single formatted diskette. Use the cpio command if you need to copy UFS files to multiple formatted diskettes. cpio recognizes end-of-media and prompts you to insert the next volume.
Use double-sided high-density 3.5-inch diskettes (diskettes are marked "DS, HD").
How to Get a Diskette Out of the Drive See the Administration Supplement for Solaris Platforms for information on getting a diskette out of the drive.
· How to Copy Files to a Single Formatted Diskette

Note - If the diskette contains a mounted file system, you must unmount the filesystem before running tar. You can unmount the file system using the umount command, or you can unmount the file system and format the diskette using the fdformat -U command.

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

  2. Insert a formatted diskette that is not write-protected into the drive.


CAUTION Caution - Copying files to a formatted diskette using the c option of tar destroys any files already on the diskette. If you want to preserve the files already on the diskette, use the tar r option described in "How to Append Files to a Formatted Diskette" on page 74.

  1. Type volcheck and press Return.

    The volcheck command makes the diskette available.

  2. If the diskette contains a PCFS, type fdformat -U /vol/dev/aliases/floppy0 and press Return. The diskette is reformatted and unmounted.


CAUTION Caution - Reformatting a diskette destroys any files or archives that were already on the diskette.

  1. Type tar cvf /vol/dev/rdiskette0/unlabeled filename filename filename ... and press Return.

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

  2. Remove the diskette from the drive.

  3. Write the names of the files on the diskette label.

In this example, two files are copied to a diskette:

  venus% cd /home/smith  
  venus% ls evaluation*  
  evaluation.doc   evaluation.doc.backup  
  venus% tar cvf /vol/dev/rdiskette0/unlabeled evaluation*  
  a evaluation.doc 86 blocks  
  a evaluation.doc.backup 84 blocks  
  venus%  

· How to List the Files on a Diskette
  1. Insert a diskette into the drive.

  2. Run volcheck(1) to make the diskette available.

  3. Type tar tvf /vol/dev/rdiskette0/unlabeled and press Return. The t option lists the table of contents for the files on the diskette.

In this example, the table of contents for the diskette contains two files:

  venus% tar tvf /vol/dev/rdiskette0/unlabeled  
  rw-rw-rw-6693/10  44032 Apr 23 14:54 1994 evaluation.doc  
  rw-rw-rw-6693/10  43008 Apr 23 14:47 1994 evaluation.doc.backup  
  venus%  

See the tar(1) manual page for more information.
If you need a multiple-volume interchange utility, use cpio. tar is only a single-volume utility.
· How to Append Files to a Formatted Diskette
  1. Change to the directory that contains the file you want to copy.

  2. Insert a formatted diskette that is not write-protected into the drive.

  3. Type tar rvf /vol/dev/rdiskette0/unlabeled filename filename filename ... and press Return.

    The file names you specify are appended to the files already on the diskette.


Note - You can use metacharacters (? and *) as part of the file names you specify. For example, to copy all documents with a .doc suffix, type *.doc as the file name argument.

  1. Remove the diskette from the drive.

  2. Write the names of the files on the diskette label.

In this example, one file is appended to the files already on the diskette:

  venus% cd /home/smith  
  venus% tar rvf /vol/dev/rdiskette0/unlabeled junk  
  a junk 1 blocks  
  venus% tar tvf /vol/dev/rdiskette0/unlabeled  
  rw-rw-rw-6693/10  44032 Apr 23 14:54 1994 evaluation.doc  
  rw-rw-rw-6693/10  43008 Apr 23 14:47 1994 evaluation.doc.backup  
  rw-rw-rw-6693/10     18 Dec 10 11:36 1993 junk  
  venus%  

· How to Retrieve Files From a Diskette
  1. Change to the directory where you want to put the files.

  2. Insert the diskette into the drive.

  3. Run volcheck(1) to make the diskette available.

  4. Type tar xvf /vol/dev/rdiskette0/unlabeled and press Return. All of the files on the diskette are copied to the current directory.

  5. Remove the diskette from the drive.

In this example, all files are copied from the diskette:

  venus% cd /home/smith/Evaluations  
  venus% tar xvf /vol/dev/rdiskette0/unlabeled evaluation*  
  x evaluation.doc, 44032 bytes, 86 tape blocks  
  x evaluation.doc.backup, 43008 bytes, 84 tape blocks  
  venus%  

To retrieve individual files from a diskette:
* Type tar xvf /vol/dev/rdiskette0/unlabeled filename filename filename ... and press Return.
The file names you specify are extracted from the diskette and placed in the current working directory.
· How to Archive Files to Multiple Diskettes
If you are copying large files or file systems onto diskettes, you want to be prompted to replace a full diskette with another formatted diskette. The cpio command provides this capability. The cpio commands you use are the same as you would use to copy files to tape, except you would specify /vol/dev/aliases/floppy0 as the device instead of the tape device name. See "Using the cpio Command" on page 69 for information on how to use cpio.

Copying Files with a Different Header Format

Archives created with the SunOS 5.x cpio command may not be compatible with older SunOS releases. The cpio command allows you to create archives that can be read with several other formats. You specify these formats using the -H option and one of these arguments:
  • crc or CRC - ASCII header with checksum
  • ustar or USTAR - IEEE/P1003 Data Interchange
  • tar or TAR - tar header and format
  • odc - ASCII header with small device numbers
  • bar - bar header and format
The syntax for using the header options is:
cpio -o -H header-option < file-list > output-archive
· How to Create an Archive Compatible with Older SunOS Releases
* Type cpio -oH odc < file-list > /dev/rmt/n and press Return.
The -H options have the same meaning for input as they do for output. If the archive was created using the -H option, you must use the same option when the archive is read back in or the cpio command will fail, as shown in this example:

  venus% find . -print | cpio -oH tar > /tmp/test  
  113 blocks  
  venus% cpio -iH bar < /tmp/test  
  cpio: Invalid header "bar" specified  
  USAGE:  
          cpio -i[bcdfkmrstuvBSV6] [-C size] [-E file] [-H hdr] [-  
  I file [-M msg]] [-R id] [patterns]  
          cpio -o[acvABLV] [-C size] [-H hdr] [-O file [-M msg]]  
          cpio -p[adlmuvLV] [-R id] directory  
  venus%  

When you create an archive using different options, always write the command syntax on the media label along with the names of the files or file system on the archive.
If you do not know which cpio options were used when an archive was created, all you can do is experiment with different combinations of the options to see which ones allow the archive to be read.
See the cpio(1) manual page for a complete list of options.

Retrieving Files Created With the bar Command

To retrieve files from diskettes that were archived using the SunOS 4.x bar command, use the -H bar option to cpio.

Note - You can only use the -H bar option with -i to retrieve files. You cannot create files with the bar header option.

· How to Retrieve bar Files From a Diskette
  1. Change to the directory where you want to put the files.

  2. Type cpio -ivH bar < /vol/dev/rdiskette/unlabeled and press Return.

    All the files on the diskette are copied to the current directory.