This chapter describes how to copy UFS files and file systems to disk, tape, and diskettes using various backup commands.
Here 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 45, The ufsdump and ufsrestore 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 ufsdump and ufsrestore.
The table below describes when to use the various backup commands.
Table 46-1 When to Use Various Backup Commands
If You Want To ... |
Then Use ... |
Reference |
---|---|---|
Back up file systems to tape | ||
Restore file systems from tape | ||
Transport files to other systems | ||
Copy files or file systems between disks | ||
Copy files to diskette |
The table below describe various backup and restore commands.
Table 46-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 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 its standard input to its 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 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 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 the standard input and 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:
$ dd if=/floppy/floppy0 of=/tmp/output.file |
Make sure the source and destination disks have the same disk geometry.
Become superuser.
Create the /reconfigure file on the system 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 |
Use the dd command to copy the master disk to the clone disk.
# dd if=/dev/rdsk/device-name of=/dev/rdsk/device-name bs=blocksize |
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 |
Block size, such as 128 Kbytes or 256 Kbytes. A large block size value decreases the time it takes to copy. |
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, changing 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: |
# 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. 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.
With cpio, 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.
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. |
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 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 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 |
See cpio(1) for more information.
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. 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 46-3 Advantages and Disadvantages of cpio, pax, and tar Commands
The tape drive and device name you use depend on the hardware and configuration for each system. See "Choosing Which Media to Use" for more information about tape drives and device names.
Things you should know before copying files to tape with the tar command:
Copying files to a tape using the -c option to tar destroys any files already on the tape at or beyond the current tape position.
You can use filename 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 filename argument.
You cannot use filename substitution wildcards for extracting 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 with the tar command.
$ tar cvf /dev/rmt/n filename ... |
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 and directories 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.
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)" for more information on listing files on a tar tape.
$ tar tvf /dev/rmt/n |
The following example copies 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.
Display the tape contents with the tar command.
$ 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. |
filename ... |
Indicates the files and directories you want to retrieve. |
The following example lists the files on the tape in drive 0.
$ tar tvf /dev/rmt/0 drwx--x--x 0/1 0 Jul 14 09:24 1999 reports/ -rw------t 0/1 30000 Jul 14 09:23 1999 reports/reportA -rw------t 0/1 31000 Jul 14 09:24 1999 reports/reportB -rw------t 0/1 32000 Jul 14 09:24 1999 reports/reportC |
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 ...] |
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. |
filename |
Specifies a file to retrieve. |
Verify the files are copied by listing the contents of the current directory.
$ ls -l |
The following example retrieves 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. See "How to List the Files on a Tape (tar)" for instructions.
See tar(1) for more information.
This section describes how to copy files with the pax command.
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.
$ pax -w -f /dev/rmt/0 filename ... |
-w |
Enables the write mode. |
-f /dev/rmt/0 |
Identifies the tape drive. |
filename ... |
Indicates the files and directories you want to copy. |
Verify 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.
$ pax -w -f /dev/rmt/0 . $ pax -f /dev/rmt/0 filea fileb filec |
See pax(1) for more information.
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 |
ls |
Provides the cpio command with a list of file names. |
cpio -oc |
Specifies that cpio should operate in copy-out mode (-o) and write header information in ASCII character format (-c). This 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 copied is shown.
Verify the files are copied to tape by using the following cpio command.
$ cpio -civt < /dev/rmt/0 |
Remove the tape from the drive and write the names of the files on the tape label.
The following example copies all of the files in the directory /export/home/kryten 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 1999, b drwx--x--x 2 kryten users 0 Jul 14 09:26 1999, letters -rw------t 1 kryten users 10000 Jul 14 09:26 1999, letter1 -rw------t 1 kryten users 10100 Jul 14 09:26 1999, letter2 -rw------t 1 kryten users 11100 Jul 14 09:27 1999, letter3 -rw------t 1 kryten users 12300 Jul 14 09:27 1999, letter4 drwx--x--x 2 kryten users 0 Jul 14 09:27 1999, memos -rw------t 1 kryten users 400 Jul 14 09:28 1999, memosmemoU -rw------t 1 kryten users 500 Jul 14 09:28 1999, memosmemoW -rw------t 1 kryten users 100 Jul 14 09:27 1999, memosmemoX -rw------t 1 kryten users 200 Jul 14 09:28 1999, memosmemoY -rw------t 1 kryten users 150 Jul 14 09:28 1999, memosmemoZ drwx--x--x 2 kryten users 0 Jul 14 09:24 1999, reports 92 blocks $ |
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 an archive tape into the tape drive.
List the files on the tape using the cpio command.
$ cpio -civt < /dev/rmt/n |
-c |
Specifies that cpio should read files in ASCII character format. |
-i |
Specifies that cpio 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 you specify. |
< /dev/rmt/n |
Specifies the input file of an existing cpio archive. |
The following example lists the files on the tape in drive 0.
$ cpio -civt < /dev/rmt/0 drwx--x--x 2 kryten users 0 Jul 14 09:34 1999, answers -rw------t 1 kryten users 800 Jul 14 09:36 1999, b drwx--x--x 2 kryten users 0 Jul 14 09:32 1999, sc.directives -rw------t 1 kryten users 200000 Jul 14 09:35 1999, direct241 drwx--x--x 2 kryten users 0 Jul 14 09:32 1999, tests -rw------t 1 kryten users 800 Jul 14 09:36 1999, 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 recreate the file on your system.
Using 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.
Copy all files from the tape to the current directory using the cpio command.
$ cpio -icvd < /dev/rmt/n |
-i |
Reads in the contents of the tape. |
-c |
Specifies that cpio should read files in ASCII character format. |
-v |
Displays the files being retrieved in a format similar to the output from the ls command. |
-d |
Create directories as needed. |
< /dev/rmt/n |
Specifies the output file. |
Verify the files are copied by listing the contents of the current directory.
$ ls -l |
The following example retrieves 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 a tape using the cpio command.
$ cpio -icv "*file" < /dev/rmt/n |
-i |
Reads in the contents of the tape. |
-c |
Specifies that cpio 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 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 input file. |
Verify the files are copied by listing the contents of the current directory.
$ ls -l |
The following example retrieves all files with the suffix chapter 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 |
See cpio(1) for more information.
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. See hosts.equiv(4) for more information.
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 or not 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 above.
To copy files to a remote tape drive, use the tar and dd commands.
$ tar cf - files | rsh remotehost dd of=/dev/rmt/n obs=blocksize |
tar cf |
Creates a tape archive and specifies the tape device. |
- (Hyphen) |
Represents a place holder for the tape device. |
files |
Identifies files to be copied. |
| rsh remotehost |
Pipes the tar command's output to a remote shell to copy the files. |
dd of=/dev/rmt/n |
Represents the output device. |
obs=blocksize |
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 |
Change to a temporary directory.
$ cd /var/tmp |
To extract files to a remote tape drive, use the tar and dd commands.
$ rsh remotehost dd if=/dev/rmt/n | tar xvBpf - |
rsh remotehost |
Indicates a remote shell that is started to extract the files from the tape device 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 used to restored the files. |
Verify that the files have been extracted.
$ ls -l /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 /var/tmp |
Before you can copy files or file systems to diskette, you must format the diskette. See Chapter 16, Formatting and Using Diskettes From the Command Line (Tasks) 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.
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").
Copying files to a formatted diskette using the -c option of tar destroys any files already on the diskette.
A diskette that already contains a tar image is not mountable.
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.
$ volcheck |
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 ... |
The file names you specify are copied to the diskette, overwriting any existing files on the diskette.
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.
$ tar tvf /vol/dev/rdiskette0/unlabeled |
Remove the diskette from the drive.
Write the names of the files on the diskette label.
The following example copies two files 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 $ tar tvf /vol/dev/rdiskette0/unlabeled |
Insert a diskette into the drive.
Run volcheck to make the diskette available.
$ volcheck |
Use the tar command to list the files on a diskette.
$ tar tvf /vol/dev/rdiskette0/unlabeled |
The following example lists the files on a diskette.
$ tar tvf /vol/dev/rdiskette0/unlabeled 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 $ |
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.
Change to the directory where you want to put the files.
Insert the diskette into the drive.
Run volcheck to make the diskette available.
$ volcheck |
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.
Verify the files have been retrieved by listing the contents of the current directory.
$ ls -l |
Remove the diskette from the drive.
The following example retrieves all the files from a diskette.
$ /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 $ ls -l |
The following example retrieves an individual file from a diskette.
$ tar xvf /vol/dev/rdiskette0/unlabeled evalutation.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. See "How to Copy All Files in a Directory to a Tape (cpio)" for information on how to use cpio.
Archives created with the SunOS 5.8 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 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 |
Use the cpio command to create the archive.
$ cpio -oH odc < file-list > /dev/rmt/n |
The -H values 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.
$ 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.
To retrieve files from diskettes that were archived using the SunOS 4.0/4.1 bar command, use the -H bar option to cpio.
You can use only the -H bar option with -i to retrieve files. You cannot create files with the bar header option.
Change to the directory where you want to put the files.
Insert the diskette into the drive.
Run volcheck to make the diskette available.
$ volcheck |
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 |