This chapter describes how to copy UFS files and file systems to disk, tape, and diskettes by using various backup commands.
This is a list of the step-by-step instructions in this chapter.
When you need to back up and restore complete file systems, use the ufsdump and ufsrestore commands described in Chapter 49, UFS Backup and Restore Commands (Reference). 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 the ufsdump and ufsrestore commands.
The following table describes when to use the various backup commands.
Table 50–1 When to Use Various Backup Commands
Task |
Command |
For More Information |
---|---|---|
Back up file systems to tape |
ufsdump | |
Create a file system snapshot |
fssnap | |
Restore file systems from tape |
ufsrestore | |
Transport files to other systems |
pax, tar, or cpio | |
Copy files or file systems between disks |
dd | |
Copy files to diskette |
tar |
The following table describes various backup and restore commands.
Table 50–2 Summary of Various Backup Commands
Command Name |
Aware of File System Boundaries? |
Support Multi Volume Backups? |
Physical or Logical Copy? |
---|---|---|---|
volcopy |
Yes |
Yes |
Physical |
tar |
No |
No |
Logical |
cpio |
No |
Yes |
Logical |
pax |
Yes |
Yes |
Logical |
dd |
Yes |
No |
Physical |
ufsdump/ufsrestore |
Yes |
Yes |
Logical |
The following sections describe the advantages and disadvantages of each method, and provide step-by-step instructions and examples of how to use the commands.
Two commands are used to copy file systems between disks:
volcopy
dd
The next section describes how to use the dd command to copy file systems between disks.
The dd command makes a literal (block-level) copy of a complete UFS file system to another file system or to a tape. By default, the dd command copies standard input to standard output.
Do not use the dd command with variable-length tape drives without first specifying an appropriate block size.
You can specify a device name in place of standard input or standard output, or both. In this example, the 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 default block size is 512 bytes.
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 standard input and standard output with this syntax:
$ dd if=input-file of=output-file |
To use the keyword=value pairs instead of the redirect symbols in the previous example, you would type the following:
$ dd if=/floppy/floppy0 of=/tmp/output.file |
Make sure that the source disk and destination disk have the same disk geometry.
Become superuser or assume an equivalent role.
Create the /reconfigure file so the system will recognize the clone disk to be added when it reboots.
# touch /reconfigure |
Shut down the system.
# init 0 |
Attach the clone disk to the system.
Boot the system.
ok boot |
Copy the master disk to the clone disk.
# dd if=/dev/rdsk/device-name of=/dev/rdsk/device-name bs=block-size |
if=/dev/rdsk/device-name |
Represents the overlap slice of the master disk device, usually slice 2. |
of=/dev/rdsk/device-name |
Represents the overlap slice of the clone disk device, usually slice 2. |
bs=blocksize |
Identifies block size, such as 128 Kbytes or 256 Kbytes. A large block size value decreases the time it takes to copy. |
For more information, see dd(1M).
Check the new file system.
# fsck /dev/rdsk/device-name |
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.
For example, change all instances of c0t3d0 with c0t1d0.
Unmount the clone disk's root (/) file system.
# umount /mnt |
Shut down the system.
# init 0 |
Boot from the clone disk to single-user mode.
# boot diskn -s |
The installboot command is not needed for the clone disk because the boot blocks are copied as part of the overlap slice.
Unconfigure the clone disk.
# sys-unconfig |
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, and so forth.
# boot diskn |
Log in as superuser to verify the system information after the system is booted.
hostname console login: |
This example shows how to copy master disk /dev/rdsk/c0t0d0s2 to clone disk /dev/rdsk/c0t2d0s2.
# touch /reconfigure # init 0 ok boot # dd if=/dev/rdsk/c0t0d0s2 of=/dev/rdsk/c0t2d0s2 bs=128k # fsck /dev/rdsk/c0t2d0s2 # mount /dev/dsk/c0t2d0s2 /mnt # cd /mnt/etc # vi vfstab (Modify entries for the new disk) # cd / # umount /mnt # init 0 # boot disk2 -s # sys-unconfig # boot disk2 |
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 copies a list of files into a single, large output file. This command 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 a 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.
With the cpio command, you frequently use commands like ls and find to list and select the files you want to copy, piping the output to the cpio command.
Become superuser or assume an equivalent role.
Change to the appropriate directory.
# cd filesystem1 |
Copy the directory tree from filesystem1 to filesystem2 by using a combination of the find and cpio commands.
# find . -print -depth | cpio -pdm filesystem2 |
. |
Starts in the current working directory. |
|
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. |
For more information, see cpio(1).
The files from the directory name you specify are copied and symbolic links are preserved.
You might also specify the -u option. This option forces an unconditional copy. Otherwise, older files do not replace newer files. This option might be useful if you want an exact copy of a directory, and some of the files being copied might already exist in the target directory.
Verify that the copy was successful by displaying the destination directory contents.
# cd filesystem2 # ls |
If appropriate, remove the source directory.
# rm -rf filesystem1 |
# cd /data1 # find . -print -depth | cpio -pdm /data2 19013 blocks # cd /data2 # ls # rm -rf /data1 |
You can use the tar, pax, and cpio commands to copy files and file systems to tape. The command you choose depends on how much flexibility and precision you require for the copy. Because all three commands use the raw device, you do not need to format or make a file system on tapes before you use them.
Table 50–3 Advantages and Disadvantages of tar, pax, and cpioCommands
The tape drive and device name you use depend on the hardware configuration for each system. For more information about tape device names, see Choosing Which Media to Use.
Here are things you should know before you copy files to tape with the tar command:
Copying files to a tape by using 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 part of the file names you specify when copying files. For example, to copy all documents with a .doc suffix, type *.doc as the file-name argument.
You cannot use file-name substitution wildcards when you extract files from a tar archive.
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.
$ tar cvf /dev/rmt/n filenames |
c |
Indicates that 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. |
filenames |
Indicates the files and directories you want to copy. Separate multiple files with spaces. |
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.
Verify that the files you copied are on the tape.
$ tar tvf /dev/rmt/n |
For more information on listing files on a tar tape, see How to List the Files on a Tape (tar).
The following example shows how to copy three files to the 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 59 tape blocks a reports/reportB 61 tape blocks a reports/reportC 63 tape blocks $ tar tvf /dev/rmt/n |
Insert a tape into the tape drive.
$ tar tvf /dev/rmt/n |
t |
Lists the table of contents for the files on the tape. |
v |
Used with the t option, and provides detailed information about the files on the tape. |
f /dev/rmt/n |
Indicates the tape device. |
The following example shows a listing of files on the tape in drive 0.
$ tar tvf /dev/rmt/0 drwx--x--x 0/1 0 Jul 14 09:24 2001 reports/ -rw------t 0/1 30000 Jul 14 09:23 2001 reports/reportA -rw------t 0/1 31000 Jul 14 09:24 2001 reports/reportB -rw------t 0/1 32000 Jul 14 09:24 2001 reports/reportC |
Change to the directory where you want to put the files.
Insert the tape into the tape drive.
Retrieve the files from the tape.
$ tar xvf /dev/rmt/n [filenames] |
x |
Indicates that the files should 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. Separate multiple files with spaces. |
For more information, see tar(1).
Verify that the files are copied.
$ ls -l |
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 |
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. For instructions on listing the files on the tape, see How to List the Files on 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.
$ pax -w -f /dev/rmt/0 filenames |
-w |
Enables the write mode. |
-f /dev/rmt/0 |
Identifies the tape drive. |
filenames |
Indicates the files and directories you want to copy. Separate multiple files with spaces. |
For more information, see pax(1).
Verify that the files are copied to tape.
$ pax -f /dev/rmt/0 |
Remove the tape from the drive and write the names of the files on the tape label.
The 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 |
Change to the directory that contains the files you want to copy.
Insert a tape that is not write-protected into the tape drive.
Copy the files to a 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). This option 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 that are copied is shown.
Verify that the files are copied to tape.
$ cpio -civt < /dev/rmt/n |
Remove the tape from the drive and write the names of the files on the tape label.
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 92 blocks $ cpio -civt < /dev/rmt/0 -rw------t 1 kryten users 400 Jul 14 09:28 2001, b drwx--x--x 2 kryten users 0 Jul 14 09:26 2001, letters -rw------t 1 kryten users 10000 Jul 14 09:26 2001, letter1 -rw------t 1 kryten users 10100 Jul 14 09:26 2001, letter2 -rw------t 1 kryten users 11100 Jul 14 09:27 2001, letter3 -rw------t 1 kryten users 12300 Jul 14 09:27 2001, letter4 drwx--x--x 2 kryten users 0 Jul 14 09:27 2001, memos -rw------t 1 kryten users 400 Jul 14 09:28 2001, memosmemoU -rw------t 1 kryten users 500 Jul 14 09:28 2001, memosmemoW -rw------t 1 kryten users 100 Jul 14 09:27 2001, memosmemoX -rw------t 1 kryten users 200 Jul 14 09:28 2001, memosmemoY -rw------t 1 kryten users 150 Jul 14 09:28 2001, memosmemoZ drwx--x--x 2 kryten users 0 Jul 14 09:24 2001, reports 92 blocks $ |
Listing the table of contents takes a long time because the cpio command must process the entire archive.
Insert an archive tape into the tape drive.
$ 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 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 that you specify. |
< /dev/rmt/n |
Specifies the input file of an existing cpio archive. |
The following example shows how to list the files on the tape in drive 0.
$ cpio -civt < /dev/rmt/0 drwx--x--x 2 kryten users 0 Jul 14 09:34 2001, answers -rw------t 1 kryten users 800 Jul 14 09:36 2001, b drwx--x--x 2 kryten users 0 Jul 14 09:32 2001, sc.directives -rw------t 1 kryten users 200000 Jul 14 09:35 2001, direct241 drwx--x--x 2 kryten users 0 Jul 14 09:32 2001, tests -rw------t 1 kryten users 800 Jul 14 09:36 2001, test13times 396 blocks |
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.
The use of absolute path names can be dangerous because you might overwrite existing files on your system.
Change to the directory where you want to put the files.
Insert the tape into the tape drive.
Extract all files from the tape.
$ cpio -icvd < /dev/rmt/n |
-i |
Extracts files from standard input. |
-c |
Specifies that cpio should read files in ASCII character format. |
-v |
Displays the files as they are retrieved in a format similar to the output from the ls command. |
-d |
Creates directories as needed. |
< /dev/rmt/n |
Specifies the output file. |
Verify that the files are copied.
$ ls -l |
The following example shows how to retrieve all files from the tape in drive 0.
$ cd /var/tmp cpio -icvd < /dev/rmt/0 answers sc.directives tests 8 blocks $ ls -l |
Change to the directory where you want to put the files.
Insert the tape into the tape drive.
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 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 must be enclosed in double quotation marks. |
< /dev/rmt/n |
Specifies the input file. |
For more information, see cpio(1).
Verify that the files are copied.
$ ls -l |
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 |
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.
For more information, see hosts.equiv(4).
An entry for the remote system must be in the local system's /etc/inet/hosts file or in the name service hosts file.
To test whether 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.
Change to the directory where you want to put the files.
Insert the tape into the tape drive.
Copy the files to a remote tape drive.
$ tar cvf - filenames | rsh remote-host dd of=/dev/rmt/n obs=block-size |
tar cf |
Creates a tape archive, lists the files as they are archived, and specifies the tape device. |
- (Hyphen) |
Represents a place holder for the tape device. |
filenames |
Identifies the files to be copied. |
| rsh remote-host |
Pipes the tar command's output to a remote shell. |
dd of=/dev/rmt/n |
Represents the output device. |
obs=block-size |
Represents the blocking factor. |
Remove the tape from the drive and write the names of the files on the tape label.
# 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 |
Insert the tape into the tape drive.
Change to a temporary directory.
$ cd /var/tmp |
Extract the files from a remote tape device.
$ rsh remote-host dd if=/dev/rmt/n | tar xvBpf - |
rsh remote-host |
Indicates a remote shell that is started to extract the files from the tape device by 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 that is used to restored the files. |
Verify that the files have been extracted.
$ ls -l /var/tmp |
$ cd /var/tmp $ 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 |
Before you can copy files or file systems to diskette, you must format the diskette. For information on how to format a diskette, see Chapter 19, Formatting Removable Media (Tasks).
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. The cpio command recognizes end-of-media and prompts you to insert the next volume.
The use of the cpio command to copy UFS files to multiple formatted diskettes is not a straightforward procedure because of volume management.
Copying files to a formatted diskette by using the tar -c command destroys any files that are already on the diskette.
A diskette that contains a tar image is not mountable.
If you need a multiple-volume interchange utility, use the cpio command. The tar command is only a single-volume utility.
For more information, see tar(1).
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.
$ volcheck |
Reformat the diskette if necessary.
$ rmformat -U /dev/rdiskette Formatting will erase all the data on disk. Do you want to continue? (y/n)y |
Copy the files to diskette.
$ tar cvf /vol/dev/aliases/floppy0 filename ... |
The file names you specify are copied to the diskette, overwriting any existing files on the diskette.
Verify that the files are copied.
$ tar tvf /vol/dev/aliases/floppy0 |
For more information on listing files, see How to List the Files on a Diskette (tar).
Remove the diskette from the drive.
Write the names of the files on the diskette label.
The following example shows how to copy two files to a diskette.
$ volcheck $ cd /home/smith $ ls evaluation* evaluation.doc evaluation.doc.backup $ tar cvf /vol/dev/aliases/floppy0 evaluation* a evaluation.doc 86 blocks a evaluation.doc.backup 84 blocks $ tar tvf /vol/dev/aliases/floppy0 |
Insert a diskette into the drive.
Make the diskette available.
$ volcheck |
$ tar tvf /vol/dev/aliases/floppy0 |
The following example shows how to list the files on a diskette.
$ volcheck tar tvf /vol/dev/aliases/floppy0 rw-rw-rw-6693/10 44032 Jun 9 15:45 evaluation.doc rw-rw-rw-6693/10 43008 Jun 9 15:55 evaluation.doc.backup $ |
Change to the directory where you want to put the files.
Insert the diskette into the drive.
Make the diskette available.
$ volcheck |
Retrieve files from the diskette.
$ tar xvf /vol/dev/aliases/floppy0 |
All files on the diskette are copied to the current directory.
Verify that the files have been retrieved.
$ ls -l |
Remove the diskette from the drive.
The following example shows how to retrieve all the files from a diskette.
$ volcheck $ cd /home/smith/Evaluations $ tar xvf /vol/dev/aliases/floppy0 x evaluation.doc, 44032 bytes, 86 tape blocks x evaluation.doc.backup, 43008 bytes, 84 tape blocks $ ls -l |
The following example shows how to retrieve an individual file from a diskette.
$ volcheck $ tar xvf /vol/dev/aliases/floppy0 evaluation.doc x evaluation.doc, 44032 bytes, 86 tape blocks $ ls -l |
The file names you specify are extracted from the diskette and placed in the current working directory.
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.
For information on how to use the cpio command, see How to Copy All Files in a Directory to a Tape (cpio).
Archives created with the SunOS 5.9 cpio command might 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 by 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 as follows:
cpio -o -H header-option < file-list > output-archive |
Use the cpio command to create the archive.
$ cpio -oH odc < file-list > /dev/rmt/n |
The -H arguments have the same meaning for input as they do for output. If the archive was created by 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 the following example.
$ 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 by 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.
For a complete list of options, see cpio(1).
To retrieve files from diskettes that were archived by using the SunOS 4.0/4.1 bar command, use the cpio -H bar command.
You can use only the -H bar option with the -i option to retrieve files. You cannot create files with the bar header option.