内に含ま
その他のドキュメント
サポート リソース
| PDF 文書ファイルをダウンロードする
Copying UFS Files and File Systems
45
- This chapter describes how copy UFS files and file systems to disk, tape, and diskettes using various backup commands.
- This is a list of the step-by-step instructions in this chapter.
-
Commands for Copying File Systems
- When you need to back up and restore complete file systems, use the ufsdump and ufsrestore commands described in Chapter 44, "Reference Information on ufsdump and ufsrestore." 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 45-1 describes when to use the various backup commands.
-
Table 45-1
| If You Want To ... | Then Use ... | Page Reference |
| Back up file systems to tape | ufsdump | page 738 |
| Restore file systems from tape | ufsrestore | page 766 |
| Transport files to other systems | pax, tar, or cpio | page 797 |
| Copy files or file systems to disk | dd | page 792 |
| Copy files to diskette | tar | page 811 |
-
Table 45-2 describe various backup and restore commands.
-
Table 45-2
Command
Name | Aware of File
System
Boundaries? | Support Multi-
Volume
Backups? |
Physical or
Logical Copy? |
| volcopy | Yes | Yes | Physical |
| tar | No | No | Logical |
| cpio | Yes | Yes | Logical |
| pax | Yes | Yes | Logical |
| dd | No | Yes | Physical |
ufsdump/
ufsrestore | Yes | Yes | Logical |
- These sections describe the advantages and disadvantages of each method and provide examples of how to use the commands.
Copying File Systems to Disk
- Two commands are used to copy file systems to disk:
-
- The next section describes how to use the dd command to copy file systems to disk.
Making a Literal File System Copy
- 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.
-
Note - Do not use the dd command 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
|
· How to Clone a Disk (dd)
-
-
Make sure the source and destination disks have the same disk geometry.
-
Become root.
-
Create the /reconfigure file on the system with the master disk so that it will recognize the clone disk once it is rebooted.
-
Shut down the system.
-
-
-
Attach the clone disk to the system.
-
Boot the system.
-
-
-
Use the dd command to copy the master disk to the clone disk.
-
# dd if=/dev/dsk/device-name of=/dev/dsk/device-name bs=blocksize
|
- In this command,
-
| if=/dev/dsk/device-name | Represents the master disk device as the input device. |
| of=/dev/dsk/device-name | Represents the clone disk device as the output device. |
| bs=blocksize | Is the block size. |
-
-
Mount the clone disk's root (/) file system.
-
# mount /dev/dsk/device-name /mnt
|
-
-
Edit the clone disk's /etc/vfstab to reference the correct device names.
-
-
Unmount the clone disk's root (/) file system.
-
-
-
Shut down the system.
-
-
-
Boot from the clone disk to single-user mode.
-
-
-
Unconfigure the clone disk.
-
- The system is shut down after it is unconfigured.
-
-
Boot from the clone disk again and provide its system information, such as host name, time zone, etc.
-
Example--Cloning a Disk (dd)
-
# init 0
ok boot
# dd if=/dev/dsk/c0t0d0s2 of=/dev/dsk/c0t2d0s2 bs=100k
# mount /dev/dsk/c0t2d0s2 /mnt
# cd /mnt/etc
# vi vfstab
# cd /
# umount /mnt
# init 0
# book disk2 -s
# sys-unconfig
# book disk2
|
Verification--Cloning a Disk (dd)
- Once the disk is configured, log in as root to verify the system information.
Copying Directories Between File Systems 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 Directories Between File Systems (cpio)
-
-
Become root.
-
Change to the appropriate directory.
-
-
-
Copy the directory tree using a combination of the find and cpio commands.
-
# find . -print -depth | cpio -pdm /filesystem2
|
- In this command,
- .........Starts in the current working directory.
-
-
-print Prints the file names.
-
| -depth | Descends the directory hierarchy and prints file names on the way back up. |
| -p | Creates a list of files. |
| -d | Creates directories as needed. |
| -m | Sets the correct modification times on directories. |
- The files from the directory name you specify are copied and symbolic links are preserved.
-
-
If appropriate, remove the source directory.
-
Verification--Copying Directories Between File Systems (cpio)
- Display the contents of the destination directory to verify the copy was successful.
-
Example--Copying Directories Between File Systems (cpio)
-
# cd /data1
# find . -print -depth | cpio -pdm /data2
19013 blocks
# cd /data2
# ls
# rm -rf /data1
|
- See cpio(1)for more information.
Copying Files and File Systems to Tape
- The pax, tar and cpio commands 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 pax to copy files and directory subtrees to a single tape. This command provides better portability that tar or cpio.
- 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.
- 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 818 for more information about tape drives and device names.
Copying Files to Tape With pax
- The pax command is used to copy files and directories to a single tape.
· How to Copy Files to a Tape (pax)
-
-
Change to the directory that contains the files you want to copy.
-
Insert a write-enabled tape into the tape drive.
-
Copy the files to tape with the pax command.
-
- In this command,
- w..........Copies the current directory contents to tape.
-
-
f /dev/rmt/0 Identifies the tape drive.
-
-
Remove the tape from the drive and write the names of the files on the tape label.
Copying Files to Tape With tar
Things You Should Know Before Copying Files to Tape With tar
-
- Copying files to a tape using the c option to tar destroys any files already on the tape.
- 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.
· How to Copy Files to a Tape (tar)
-
-
Change to the directory that contains the files you want to copy.
-
Insert a write-enabled tape into the tape drive.
-
Copy the files to tape with the tar command.
-
$ tar cvf /dev/rmt/n filename filename filename
|
- In this command,
-
| c | Indicates you want to create 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. |
| filename | Indicates the files you want to copy. |
- The file names you specify are copied to the tape, overwriting any existing files on the tape.
-
-
Remove the tape from the drive and write the names of the files on the tape label.
Verification--Copying Files to a Tape (tar)
- Verify that the files copied are on the tape using the tar command with the t option, which displays the tape's contents. See "How to List the Files on a Tape (tar)" on page 800 for more information on listing files on a tar tape.
-
Example--Copying Files to a Tape (tar)
- In this example, three files are copied to a tape in tape drive 0.
-
$ cd /export/home/kryten
$ ls reports
reportA reportB reportC
$ tar cvf /dev/rmt/0 reports
a reports/ 0 tape blocks
a reports/reportA 2 tape blocks
a reports/reportB 5 tape blocks
a reports/reportC 6 tape blocks
$
|
· How to List the Files on a Tape (tar)
-
-
Insert a tape into the tape drive.
-
Display the tape contents with the tar command.
-
- In this command,
-
| t | Lists the table of contents for the files on the tape. |
| v | Used with the t option provides detailed information about the files on the tape. |
-
-
f /dev/rmt/n Indicates the tape device.
Example--Listing the Files on a Tape (tar)
- In this example, the table of contents for the tape in drive 0 contains three files.
-
$ tar tvf /dev/rmt/0
drwxr-xr-x101/100 0 Oct 24 11:05 1994 reports/
-rw-r--r--101/100 611 Oct 24 11:05 1994 reports/reportA
-rw-r--r--101/100 2322 Oct 24 11:05 1994 reports/reportB
-rw-r--r--101/100 2596 Oct 24 11:05 1994 reports/reportC
|
· How to Retrieve Files From a Tape (tar)
-
-
Change to the directory where you want to put the files.
-
Insert the tape into the tape drive.
-
Retrieve files from the tape using the tar command.
-
$ tar xvf /dev/rmt/n filename filename
|
- In this command,
-
| x | 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. |
| v | Displays the name of each file as it is archived. |
| f /dev/rmt/n | Indicates the tape device containing the archive. |
Example--Retrieving the Files on a Tape (tar)
- In this example, all files are copied from the tape in drive 0.
-
$ cd /usr/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
|
-
Note - The names of the files extracted from the tape must 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 800 for instructions.
- See tar(1) for more information.
· How to Copy All Files in a Directory to a Tape (cpio)
-
-
Insert a tape that is not write-protected into the tape drive.
-
Copy files to a tape using the ls and cpio commands.
-
$ ls | cpio -oc > /dev/rmt/n
|
- In this command,
-
| ls | Provides the cpio command with a list of file names. |
| cpio -oc | Specifies that cpio should read from standard output (-o) and read information in ASCII character format (c). |
-
-
> /dev/rmt/n Specifies the output file.
- 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.
-
-
Remove the tape from the drive and write the names of the files on the tape label.
Verification--Copying All Files in a Directory to a Tape (cpio)
-
$ cpio -civt < /tmp/cpio.file
drwxr-xr-x 2 kryten users 0 Oct 24 11:05 1994, letters
drwxr-xr-x 2 kryten users 0 Oct 24 11:05 1994, memos
drwxr-xr-x 2 kryten users 0 Nov 8 14:14 1994, reports
8 blocks
$
|
Example--Copying All Files in a Directory to a Tape (cpio)
- In this example, all of the files in the directory /export/home/kryten are copied to the tape in tape drive 0.
-
$ cd /export/home/kryten
$ ls | cpio -oc > /dev/rmt/0
8 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.
-
-
Insert a tape into the tape drive.
-
List the files on tape using the cpio command.
-
$ cpio -civt < /dev/rmt/n
|
- In this command,
-
| c | Specifies that cpio should read files in ASCII character format. |
| i | Reads in the contents of the tape. |
-
| 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 output file.
Example--Listing the Files on a Tape (cpio)
- In this example, the table of contents for the tape in drive 0 contains three files.
-
$ cpio -civt < /dev/rmt/0
drwxr-xr-x 2 rimmer users 0 Oct 28 09:17 1994, answers
drwxr-xr-x 2 rimmer users 0 Oct 28 09:17 1994, sc.directives
drwxr-xr-x 2 rimmer users 0 Oct 28 09:17 1994, tests
8 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 re-create the file on your system.
-
Caution - Using absolute path names can be dangerous because you will overwrite the original files.
-
-
Change to the directory where you want to put the files.
-
Insert the tape into the tape drive.
-
-
Copy all files from the tape to the current directory using the cpio command.
-
- In this command,
-
| i | Reads in the contents of the tape. |
| c | Specifies that cpio should read files in ASCII character format. |
| v | Displays the output in a format similar to the output from the ls -l command. |
-
-
< /dev/rmt/n Specifies the output file.
Example--Retrieving All Files From a Tape (cpio)
- In this example, all files are copied from the tape in drive 0.
-
$ cd /usr/tmp
cpio -icv < /dev/rmt/0
answers
sc.directives
tests
8 blocks
|
· How to Retrieve Specific Files From a Tape (cpio)
-
-
Change to the directory where you want to put the files.
-
Insert the tape into the tape drive.
-
Retrieve a subset of files from a tape using the cpio command.
-
$ cpio -icv "*file" < /dev/rmt/n
|
- In this command,
-
| i | Reads in the contents of the tape. |
| c | Specifies that cpio should read files in ASCII character format. |
| v | Displays the output in a format similar to the output from the ls -l 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 output file.
Example--Retrieving Specified Files From a Tape (cpio)
- In this example, all files with suffix chapter are copied from tape drive 0.
-
$ cd /home/smith/Book
$ cpio -icv "*chapter" < /dev/rmt/0
Boot.chapter
Directory.chapter
Install.chapter
Intro.chapter
31 blocks
|
- See cpio(1) for more information.
· How to Copy Files to a Remote Tape Drive (tar and dd)
-
-
The following prerequisites must be met to use a remote tape drive:
-
- A user entry must be in the remote system's /.rhost file
- An entry for the remote system must be in the local system's /etc/inet/hosts file
-
-
To copy files to a remote tape drive use the tar and dd commands.
-
$ tar cf - files | rsh remotehost dd of=/dev/rmt/n bs=blocksize
|
- In this command,
-
| tar cf | Creates a tape archive and specifies the tape device. |
| - | Represents a placeholder for the tape device. |
| files | Identifies files to be copied. |
| | rsh remotehost | Pipe tar command to a remote shell to copy the files. |
| dd of=/dev/rmt/w | Represents the output device. |
| bs=blocksize | Represents the blocking factor. |
-
-
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 bs=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
0+2 records in
0+2 records out
|
· How to Extract Files From a Remote Tape Drive
-
-
Change to a temporary directory.
-
-
-
To extract files to a remote tape drive use the tar and dd commands.
-
$ rsh remotehost dd if=/dev/rmt/n | tar xvBpf -
|
- In this command,
-
rsh remotehost.....Is a remote shell that is started to extract the files from the tape device using the dd command.
-
-
dd if=/dev/rmt/n Represents in the input device.
| tar xvBpf - Pipes the output of the dd command to the tar
command used to restored the files.
Verification--Extracting Files From a Remote Tape Drive
- Verify that the files have been extracted.
-
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
|
Copying Files and File Systems to Diskette
- Before you can copy files or file systems to diskette, you must format the diskette. See Chapter 14, "Formatting and Using Diskettes From the Command Line" 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.
-
Note - Using the cpio command to copy UFS files to multiple formatted diskettes is not a straightforward procedure because of Volume Management.
- Use double-sided high-density 3.5-inch diskettes (diskettes are marked "DS, HD").
Things You Should Know When Copying Files to Diskettes
-
- If the diskette contains a mounted file system, you must unmount the file system 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.
- Copying files to a formatted diskette using the c option of tar destroys any files already on the diskette.
- Reformatting a diskette destroys any files or archives that were already on the diskette.
· How to Copy Files to a Single Formatted Diskette (tar)
-
-
Change to the directory that contains the files you want to copy.
-
Insert a formatted diskette that is not write-protected into the drive.
-
Make the diskette available using the volcheck command.
-
Unmount any file system on the diskette and reformat it.
-
$ fdformat -U /vol/dev/aliases/floppy0
|
-
-
Copy the files to diskette using the tar command.
-
$ tar cvf /vol/dev/rdiskette0/unlabeled filename filename filename
|
- The file names you specify are copied to the diskette, overwriting any existing files on the diskette.
-
-
Remove the diskette from the drive.
-
Write the names of the files on the diskette label.
Verification--Copying Files to a Single Formatted Diskette (tar)
-
$ tar tvf /vol/dev/rdiskette0/unlabeled
|
- Verify that the files copied are on the diskette using the tar command with the t option, which displays the diskette's contents. See "How to List the Files on a Diskette (tar)" for more information on listing files.
Example--Copying Files to a Single Formatted Diskette (tar)
- In this example, two files are copied to a diskette:
-
$ cd /home/smith
$ ls evaluation*
evaluation.doc evaluation.doc.backup
$ tar cvf /vol/dev/rdiskette0/unlabeled evaluation*
a evaluation.doc 86 blocks
a evaluation.doc.backup 84 blocks
|
· How to List the Files on a Diskette (tar)
-
-
Insert a diskette into the drive.
-
Run volcheck to make the diskette available.
-
Use the tar command to list the files on a diskette.
-
$ tar tvf /vol/dev/rdiskette0/unlabeled
|
Example--Listing the Files on a Diskette (tar)
- In this example, the table of contents for the diskette shows two files:
-
$ 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
$
|
- See tar(1) for more information.
- If you need a multiple-volume interchange utility, use the cpio command. The tar command is only a single-volume utility.
· How to Retrieve Files From a Diskette (tar)
-
-
Change to the directory where you want to put the files.
-
Insert the diskette into the drive.
-
Run volcheck to make the diskette available.
-
Use the tar command to retrieve files from a diskette.
-
$ tar xvf /vol/dev/rdiskette0/unlabeled
|
- All of the files on the diskette are copied to the current directory.
-
-
Remove the diskette from the drive.
Examples--Retrieving Files From a Diskette (tar)
- In this example, all files are copied from the diskette:
-
$ cd /home/smith/Evaluations
$ tar xvf /vol/dev/rdiskette0/unlabeled
x evaluation.doc, 44032 bytes, 86 tape blocks
x evaluation.doc.backup, 43008 bytes, 84 tape blocks
|
- Use the tar command to retrieve individual files from a diskette.
-
$ tar xvf /vol/dev/rdiskette0/unlabeled filename filename filename
|
- The file names you specify are extracted from the diskette and placed in the current working directory.
Verification--Retrieving Files From a Diskette (tar)
-
· 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 "How to Copy All Files in a Directory to a Tape (cpio)" on page 803 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 for Older SunOS Releases
- Use the cpio command to create the archive.
-
$ cpio -oH odc < file-list > /dev/rmt/n
|
- 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 below.
Example--Creating an Archive for Older SunOS Releases
-
$ find . -print | cpio -oH tar > /tmp/test
113 blocks
$ 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
|
- 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 cpio(1)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
-
-
Change to the directory where you want to put the files.
-
Use the cpio command to retrieve bar files from a diskette. All the files on the diskette are copied to the current directory.
-
$ cpio -ivH bar < /vol/dev/rdiskette/unlabeled
|
|
|