|
|
|
7.
Continue to use the ufsrestore command as needed.
# ufsrestore rvf /dev/rmt/n
The next level tape is restored.
8.
Repeat Step 6 on page 595 and Step 7 on page 596 for each additional tape.
9.
Verify the file system is restored.
# ls
10. Remove the restoresymtable file.
# rm restoresymtable
Removes the restoresymtable file that is created and used by ufsrestore to
check-point the restore.
11. Change to the root (/) directory.
# cd /
12. Unmount the newly created file system.
# umount /mnt
13. Check the new file system.
# fsck /dev/rdsk/device-name
The restored file system is checked for consistency.
14. Create the boot blocks on the root partition by using the installboot(1M)
command.
#
installboot
/usr/platform/‘uname-i‘/lib/fs/ufs/bootblk /dev/rdsk/devicename
See “SPARC: Example—Restoring the root (/) File System” on page 597 for an
example of using the installboot command on a SPARC based system or “IA:
Example—Restoring the root (/) File System” on page 597 for an example of
using the installboot command on an IA based system.
596
15. Insert a new tape in the tape drive.
16. Back up the new file system.
# ufsdump 0uf /dev/rmt/n /dev/rdsk/device-name
A level 0 backup is performed. Always do an immediate backup of a newly
created file system because ufsrestore repositions the files and changes the
inode allocation.
17. Repeat steps 5 through 18 for the /usr file system, if necessary.
18. Reboot the system.
# init 6
The system is rebooted.
SPARC: Example—Restoring the root (/) File System
# mount /dev/dsk/c0t3d0s0 /mnt
# cd /mnt
# tapes
# ufsrestore rvf /dev/rmt/0
# ls
# rm restoresymtable
# cd /
# umount /mnt
# fsck /dev/rdsk/c0t3d0s0
# installboot /usr/platform/sun4m/lib/fs/ufs/bootblk /dev/rdsk/c0t3d0s0
# ufsdump 0uf /dev/rmt/0 /dev/rdsk/c0t3d0s0
# init 6
IA: Example—Restoring the root (/) File System
# mount /dev/dsk/c0t3d0s0 /mnt
# cd /mnt
# tapes
# ufsrestore rvf /dev/rmt/0
# ls
# rm restoresymtable
# cd /
# umount /mnt
# fsck /dev/rdsk/c0t3d0s0
# installboot /usr/platform/‘uname -i‘/lib/fs/ufs/pboot /usr/platform/‘uname -i‘/lib/fs/
(continued)
Restoring Files and File Systems (Tasks)
597
(Continuation)
ufs/bootblk /dev/rdsk/c0t3d0s0
# ufsdump 0uf /dev/rmt/0 /dev/rdsk/c0t3d0s0
# init 6
598
CHAPTER
45
The ufsdump and ufsrestore
Commands (Reference)
This chapter contains reference information on the ufsdump and ufsrestore
commands.
Here is a list of information in this chapter.
“How ufsdump Works” on page 599
“Options and Arguments for the ufsdump Command” on page 604
“The ufsdump Command and Security Issues” on page 607
“Options and Arguments for the ufsrestore Command” on page 607
How ufsdump Works
The ufsdump command makes two passes when backing up a file system. On the
first pass, it scans the raw device file for the file system and builds a table of
directories and files in memory. It then writes the table to the backup media. In the
second pass, ufsdump goes through the inodes in numerical order, reading the file
contents and writing the data to the media.
Determining Device Characteristics
The ufsdump command needs to know only an appropriate block size and how to
detect the end of media.
599
Detecting the End of Media
ufsdump writes a sequence of fixed-size records. When ufsdump receives
notification that a record was only partially written, it assumes that it has reached
the physical end of the media. This method works for most devices. If a device is not
able to notify ufsdump that only a partial record has been written, a media error
occurs as ufsdump tries to write.
Note - DAT devices and 8mm tape devices detect end-of-media. Cartridge tape
devices and 1/2-inch tape devices do not detect end-of-media.
Copying Data With ufsdump
The ufsdump command copies data only from the raw disk slice. If the file system is
still active, anything in memory buffers is probably not copied. The backup done by
ufsdump does not copy free blocks, nor does it make an image of the disk slice. If
symbolic links point to files on other slices, the link itself is copied.
Role of the /etc/dumpdates File
The ufsdump command, when used with the −u option, maintains and updates the
/etc/dumpdates file. Each line in /etc/dumpdates shows the file system backed
up, the level of the last backup, and the day, date, and time of the backup. Here is a
typical /etc/dumpdates file from a file server:
/dev/rdsk/c0t0d0s0
9 Tue Jul 13 10:58:12 1999
/dev/rdsk/c0t0d0s0
0 Tue Jul 13 10:46:09 1999
/dev/rdsk/c0t0d0s1
0 Tue Jul 13 13:41:04 1999
When you do an incremental backup, the ufsdump command consults
/etc/dumpdates to find the date of the most recent backup of the next lower level.
Then it copies to the media all files that were modified since the date of that
lower-level backup. After the backup is complete, a new information line, describing
the backup you just completed, replaces the information line for the previous backup
at that level.
Use the /etc/dumpdates file to verify that backups are being done. This
verification is particularly important if you are having equipment problems. If a
backup cannot be completed because of equipment failure, the backup is not
recorded in the /etc/dumpdates file.
600
If you need to restore an entire disk, check the /etc/dumpdates file for a list of the
most recent dates and levels of backups so that you can determine which tapes you
need in order to restore the entire file system.
Note - The /etc/dumpdates file is a text file that can be edited, but edit it only at
your own risk. If you make changes to the file that do not match your archive tapes,
you might not be able to find the tapes (or files) you need.
Backup Device (dump-file) Argument
The dump-file argument (to the −f option) specifies the destination of the backup,
which can be one of the following:
Local tape drive or diskette drive
Remote tape drive or diskette drive
Standard output
Use this argument when the destination is not the default local tape drive
/dev/rmt/0. If you use the −f option, then you must specify a value for dump-file.
Note - The dump-file argument can also point to a file on a local or remote disk,
which, if used by mistake, can fill up a file system.
Local Tape or Diskette Drive
Typically, dump-file specifies a raw device file for a tape or diskette drive. When
ufsdump writes to an output device, it creates a single backup file that might span
multiple tapes or diskettes.
You specify the tape or diskette device on your system using a device abbreviation.
The first device is always 0. For example, if you have a SCSI tape controller and one
QIC-24 tape drive that uses medium-density formatting, use this device name:
/dev/rmt/0m
When you specify a tape device name, you can also type the letter “n” at the end of
the name to indicate that the tape drive should not rewind after the backup is
completed. For example:
/dev/rmt/0mn
Use the “no-rewind” option if you want to put more than one file onto the tape. If
you run out of space during a backup, the tape does not rewind before ufsdump
asks for a new tape. See “Backup Device Names” on page 640 for a complete
description of device naming conventions.
The ufsdump and ufsrestore Commands (Reference)
601
Remote Tape or Diskette Drive
You specify a remote tape or diskette drive using the syntax host:device. ufsdump
writes to the remote device when root on the local system has access to the remote
system. If you usually run ufsdump as root, the name of the local system must be
included in the /.rhosts file on the remote system. If you specify the device as
user@host:device, ufsdump tries to access the device on the remote system as the
specified user. In this case, the specified user must be included in the /.rhosts file
on the remote system.
Use the naming convention for the device that matches the operating system for the
system on which the device resides, not the system from which you run the
ufsdump command. If the drive is on a system that is running a previous SunOS
release (for example, 4.1.1), use the SunOS 4.1 device name (for example,
/dev/rst0). If the system is running Solaris software, use the SunOS 5.8 convention
(for example, /dev/rmt/0).
Note - You must specify remote devices explicitly with the dump-file argument. In
previous SunOS releases, the rdump command directed the output to the remote
device defined by the dumphost alias. ufsdump does not have an rufsdump
counterpart.
Using Standard Output With ufsdump
When you specify a dash (-) as the dump-file argument, ufsdump writes to the
standard output.
Note - The −v option (verify) does not work when the dump-file argument is
standard output.
You can use the ufsdump and ufsrestore commands in a pipeline to copy a file
system by writing to the standard output with ufsdump and reading from the
standard input with ufsrestore, as shown in this example:
# ufsdump 0f - /dev/rdsk/c0t0d0s7 | (cd /home; ufsrestore xf -)
Specifying Files to Back Up
You must always include files-to-backup as the last argument on the command line.
This argument specifies the source or contents of the backup. It usually identifies a
file system but can also identify individual files or directories.
For a file system, specify the raw device file for a disk slice. It includes the disk
controller abbreviation (c), the target number (t) for SCSI devices only, a number
indicating the disk number (d), and the slice number (s). For example, if you have a
602
SCSI disk controller on your standalone system (or server) and you want to back up
/usr located in slice 6, specify the device as follows:
/dev/rdsk/c0t0d0s6
You can specify the file system by its mount point directory (for example, /home), as
long as there is an entry for it in the /etc/vfstab file.
See “Backup Device Names” on page 640 for a complete description of device
naming conventions.
For individual files or directories, type one or more names separated by spaces.
Note - When you use ufsdump to back up one or more directories or files (rather
than a whole file system), a level 0 backup is done. Incremental backups do not apply.
End-of-Media Detection
The ufsdump command automatically detects the end-of-media for most devices.
Therefore, you do not usually need to use the −c, −d, −s, and −t options to perform
multivolume backups.
The only time you need to use the end-of-media options is when ufsdump does not
understand the way the device detects the end-of-media or you are going to restore
the files on a system with an older version of the restore command. To ensure
compatibility with older versions of the restore command, the size option can still
force ufsdump to go to the next tape or diskette before reaching the end of the
current tape or diskette.
Specifying Tape Characteristics
If you do not specify any tape characteristics, the ufsdump command uses a set of
defaults. You can specify tape cartridge (c), density (d), size (s), and number of
tracks (t). Note that you can specify the options in any order as long as the
arguments that follow match the order of the options.
Limitations of the ufsdump Command
The table below lists tasks you cannot perform with the ufsdump command.
The ufsdump and ufsrestore Commands (Reference)
603
TABLE 45-1
Tasks You Cannot Perform With the ufsdump Command
The ufsdump Command Does Not ...
Comments
Automatically calculate the number of tapes
You can use the dry run mode (S option) to
or diskettes needed for backing up file
determine the amount of space that is
systems
needed before actually backing up file
systems.
Provide built-in error checking to minimize
—
problems when backing up an active file
system
Enable you to back up files that are remotely Files on the server must be backed up on
mounted from a server
the server itself. Users are denied permission
to run ufsdump on files they own that are
located on a server.
Options and Arguments for the
ufsdump Command
This section describes in detail the options and arguments for the ufsdump
command. The syntax for the ufsdump command is:
/usr/sbin/ufsdump [options] [arguments] files-to-back-up
Is a single string of one-letter option names.
options
Identifies option arguments and might be multiple strings.
arguments
The option letters and the arguments that go with them
must be in the same order.
Identifies the files to back up; and these arguments must
files-to-back-up
always come last.
Default ufsdump Options
If you run the ufsdump command without any options, use this syntax:
# ufsdump files-to-back-up
604
ufsdump uses these options, by default:
ufsdump 9uf /dev/rmt/0 files-to-back-up
These options do a level 9 incremental backup to the default tape drive at its
preferred density.
Options for the ufsdump Command
The table below describes the options for the ufsdump command.
TABLE 45-2
Options for the ufsdump Command
Option
Description
Backup level. Level 0 is for a full backup of the whole file
0-9
system specified by files-to-backup. Levels 1-9 are for incremental
backups of files that have changed since the last lower-level
backup.
a archive-file
Archive file. Store (archive) a backup table of contents in a
specified file on the disk. The file can be understood only by
ufsrestore, which uses it to determine whether a file to be
restored is present in a backup file, and if so, on which volume
of the media it resides.
b factor
Blocking factor. The number of 512-byte blocks to write to tape
at a time.
c
Cartridge. Back up to cartridge tape. When end-of-media
detection applies, this option sets the block size to 126.
d bpi
Tape density. You need to use this option only when ufsdump
cannot detect the end of the media.
D
Diskette. Back up to diskette.
f dump-file
Dump file. Write the files to the destination specified by
dump-file instead of the default device. If the file is specified as
user@system:device, ufsdump attempts to execute as the specified
user on the remote system. The specified user must have a /
.rhosts file on the remote system that allows the user invoking
the command on the local system to access the remote system.
The ufsdump and ufsrestore Commands (Reference)
605
TABLE 45-2
Options for the ufsdump Command
(continued)
Option
Description
l
Autoload. Use this option if you have an autoloading
(stackloader) tape drive. When the end of a tape is reached, this
option takes the drive offline and waits up to two minutes for
the tape drive to be ready again. If the drive is ready within
two minutes, it continues. If it is not ready after two minutes, it
prompts the operator to load another tape.
n
Notify. When intervention is needed, send a message to all
terminals of all users in the sys group.
o
Offline. When finished with a tape or diskette, take the drive
offline, rewind (if tape), and if possible remove the media (for
example, eject a diskette or remove 8-mm autoloaded tape).
s size
Size. Specify the length of tapes in feet or number of 1024-byte
blocks for diskettes. You need to use this option only when
ufsdump cannot detect the end of the media.
S
Estimate size of backup. Determine the amount of space that is
needed to perform the backup, without actually doing it, and
output a single number indicating the estimated size of the
backup in bytes.
t tracks
Tracks. Specify the number of tracks for 1/4-inch cartridge tape.
You need to use this option only when ufsdump cannot detect
the end of the media.
u
Update the dump record. For a completed backup on a file
system, add an entry to the /etc/dumpdates file. The entry
indicates the device name for the file system’s disk slice, the
backup level (0-9), and the date. No record is written when you
do not use the u option or when you back up individual files or
directories. If a record already exists for a backup at the same
level, it is replaced.
v
Verify. After each tape or diskette is written, verify the contents
of the media against the source file system. If any discrepancies
occur, prompt the operator to mount new media, then repeat
the process. Use this option only on an unmounted file system,
because any activity in the file system causes it to report
discrepancies.
606
TABLE 45-2
Options for the ufsdump Command
(continued)
Option
Description
w
Warning. List the file systems appearing in /etc/dumpdates
that have not been backed up within a day. When you use this
option all other options are ignored.
W
Warning with highlight. Show all the file systems that appear in
/etc/dumpdates and highlight those file systems that have
not been backed up within a day. When you use this option all
other options are ignored.
Note - The /etc/vfstab file does not contain information about how often to back
up a file system.
The ufsdump Command and Security
Issues
If you are concerned about security:
Require root access for the ufsdump command.
Ensure root access entries are removed from /.rhosts files on clients and servers
if doing centralized backups.
For general information on security, see “Managing System Security (Overview)”
in System Administration Guide, Volume
2.
Options and Arguments for the
ufsrestore Command
ufsrestore Command Syntax
The syntax of the ufsrestore command is:
ufsrestore [options][arguments][filename …]
The ufsdump and ufsrestore Commands (Reference)
607
options
Is a single string of one-letter option names. You must
choose one and only one of these options: i, r, R, t, or x.
Follows the option string with the arguments that match the
arguments
options. The option names and the arguments that go with
them must be in the same order.
Specifies files to be restored as arguments to the x or t
filename
options, and must always come last.
ufsrestore Options and Arguments
You must use one (and only one) of the ufsrestore options shown in the table
below.
TABLE 45-3
One Required Option for the ufsrestore Command
Option
Description
i
Interactive. Runs ufsrestore in an interactive mode. In this
mode, you can use a limited set of shell-like commands to
browse the contents of the media and select individual files or
directories to restore. See “Commands for Interactive Restore”
on page 610 for a list of available commands.
r
Recursive. Restores the entire contents of the media into the
current working directory (which should be the top level of the
file system). Information used to restore incremental dumps on
top of the full dump (for example, restoresymtable) is also
included. To completely restore a file system, use this option to
restore the full (level 0) dump and each subsequent incremental
dump. Although intended for a new file system (one just
created with the newfs command), files not on the backup
media are preserved.
R
Resume restoring. Prompts for the volume from which to
resume restoring and restarts from a checkpoint. You rerun the
ufsrestore command with this option after a full restore (r
option) is interrupted.
608
TABLE 45-3
One Required Option for the ufsrestore Command
(continued)
Option
Description
x [filename…]
Extract. Selectively restores the files you specify by the filename
argument. filename can be a list of files and directories. All files
under a specified directory are restored unless you also use the
h option. If you omit filename or enter “.” for the root directory,
all files on all volumes of the media (or from standard input)
are restored. Existing files are overwritten, and warnings are
displayed.
t [filename…]
Table of contents. Checks the files specified in the filename
argument against the media. For each file, lists the full file name
and the inode number (if the file is found) or indicates the file is
not on the “volume” (meaning any volume in a multivolume
dump). If you do not enter the filename argument, all files on all
volumes of the media are listed (without distinguishing on
which volume files are located). If you also use the h option,
only the directory files specified in filename, not their contents,
are checked and listed. The table of contents is read from the
first volume of the media, or, if you use the a option, from the
specified archive file. This option is mutually exclusive with the
x and r options.
Additional ufsrestore options are described in the table below.
TABLE 45-4
Additional Options for the ufsrestore Command
Option
Description
Takes the dump table of contents from the specified archive-file
a archive-file [filename…]
instead of from the media (first volume). You can use this option
in combination with the t, i, or x options to check for the files
in the dump without having to mount any media. If you use it
with the x and interactive extract options, you are prompted to
mount the appropriate volume before extracting the file(s).
Blocking factor. Number of 512-byte blocks read from tape at a
b factor
time. By default, ufsrestore tries to figure out the block size
that was used in writing the tape.
d
Debug. Turn on debugging messages.
The ufsdump and ufsrestore Commands (Reference)
609
TABLE 45-4
Additional Options for the ufsrestore Command
(continued)
Option
Description
f backup-file
Backup file. Reads the files from the source indicated by
backup-file, instead of from the default device file /dev/rmt/0m.
If you use the f option, you must specify a value for
backup-file. When backup-file is of the form system:device,
ufsrestore reads from the remote device. You can also use
the backup-file argument to specify a file on a local or remote
disk. If backup-file is ‘-’, the files are read from standard input.
h
Turns off directory expansion. Only the directory file you
specify is extracted or listed.
m
Restores specified files into the current directory on the disk
regardless of where they are located in the backup hierarchy
and renames them with their inode number. For example, if the
current working directory is /files, a file in the backup
named ./dready/fcs/test with inode number 42, is
restored as /files/42. This option is useful only when you
are extracting a few files.
s n
Skips to the nth backup file on the media (first volume). This
option is useful when you put more than one backup on a
single tape.
v
Verbose. Displays the names and inode numbers of each file as
it is restored.
y
Continues when errors occur reading the media and tries to
skip over bad blocks instead of stopping and asking whether to
continue. This option tells the command to assume a yes
response.
Commands for Interactive Restore
610
TABLE 45-5
Commands for Interactive Restore
Option
Description
Lists the contents of either the current directory or the specified
ls [directory-name]
directory. Directories are marked by a / suffix and entries in the
current list to be restored (extracted) are marked by an * prefix.
Inode numbers are shown if the verbose option is used.
cd directory-name
Changes to the specified directory in the backup hierarchy.
add [filename]
Adds the current directory or the specified file or directory to
the list of files to extract (restore). If you do not use the h
option, all files in a specified directory and its subdirectories are
added to the list. All the files you want to restore to a directory
might not be on a single backup tape or diskette. You might
need to restore from multiple backups at different levels to get
the latest revisions of all the files.
delete [filename]
Deletes the current directory or the specified file or directory
from the list of files to extract (restore). If you do not use the h
option, all files in the specified directory and its subdirectories
are deleted from the list. The files and directories are deleted
only from the extract list you are building. They are not deleted
from the media or the file system.
extract
Extracts the files in the list and restores them relative to the
current working directory on the disk. Specify 1 when asked
for a volume number for a single-volume backup. If you are
doing a multitape or multidiskette restore and restoring a small
number of files, start with the last tape or diskette instead.
help
Displays a list of commands you can use in interactive mode.
pwd
Displays the path name of the current working directory in the
backup hierarchy.
q
Quits interactive mode without restoring any additional files.
setmodes
Lets you set the mode for files to be restored to match the mode
of the root directory of the file system from which they were
backed up. You are prompted with: set owner/mode for ’.’
[yn]? Type y (for yes) to set the mode (permissions, owner,
times) of the current directory to match the root directory of the
file system from which they were backed up. Use this mode
when restoring a whole file system.
Type n (for no) to leave the mode of the current directory
unchanged. Use this mode when restoring part of a backup to a
directory other than the one from which the files were backed
up.
The ufsdump and ufsrestore Commands (Reference)
611
TABLE 45-5
Commands for Interactive Restore
(continued)
Option
Description
verbose
Turns on or off the verbose option (which can also be entered
as v on the command line outside of interactive mode). When
verbose is on, the interactive ls command lists inode numbers
and the ufsrestore command displays information on each
file as it is extracted.
what
Displays the backup header from the tape or diskette.
612
CHAPTER
46
Copying UFS Files and File Systems
(Tasks)
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:
“How to Clone a Disk (dd)” on page 616
“How to Copy Directories Between File Systems (cpio)” on page 619
“How to Copy Files to a Tape (tar)” on page 623
“How to List the Files on a Tape (tar)” on page 624
“How to Retrieve Files From a Tape (tar)” on page 625
“How to Copy All Files in a Directory to a Tape (cpio)” on page 627
“How to List the Files on a Tape (cpio)” on page 628
“How to Retrieve All Files From a Tape (cpio)” on page 629
“How to Retrieve Specific Files From a Tape (cpio)” on page 630
“How to Copy Files to a Remote Tape Drive (tar and dd)” on page 631
“How to Extract Files From a Remote Tape Drive” on page 632
“How to Copy Files to a Single Formatted Diskette (tar)” on page 634
“How to List the Files on a Diskette (tar)” on page 635
“How to Retrieve Files From a Diskette (tar)” on page 636
“How to Archive Files to Multiple Diskettes” on page 637
“How to Create an Archive for Older SunOS Releases” on page 637
“How to Retrieve bar Files From a Diskette” on page 638
613
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 45. 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
“How to Do
ufsdump(1M)
Backups to
Tape” on page
574
Restore file systems from tape
ufsrestore(1M)
“How to Restore
a Complete File
System” on
page 592
Transport files to other systems
pax(1), tar(1), or
“Copying Files
cpio(1)
and File
Systems to
Tape” on page
621
Copy files or file systems between disks
dd(1M)
“How to Clone
a Disk (dd)” on
page 616
Copy files to diskette
“How to Copy
tar(1)
Files to a Single
Formatted
Diskette (tar)”
on page 634
The table below describe various backup and restore commands.
614
TABLE 46-2
Summary of Various Backup Commands
Aware of File
Support
System
Multi-Volume
Physical or
Command Name
Boundaries?
Backups?
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.
Copying File Systems Between Disks
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.
Making a Literal File System Copy
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.
Copying UFS Files and File Systems (Tasks)
615
Note - 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
How to Clone a Disk (dd)
1. Make sure the source and destination disks have the same disk geometry.
2. Become superuser.
3. Create the /reconfigure file on the system so the system will recognize the
clone disk to be added when it reboots.
# touch /reconfigure
4. Shut down the system.
# init 0
616
5. Attach the clone disk to the system.
6. Boot the system.
ok boot
7. 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
Represents the overlap slice of the master disk
if=/dev/rdsk/device-name
device, usually slice 2.
of=/dev/rdsk/device-name
Represents the overlap slice of the clone disk device,
usually slice 2.
Block size, such as 128 Kbytes or 256 Kbytes. A large
bs=blocksize
block size value decreases the time it takes to copy.
8. Check the new file system.
# fsck /dev/rdsk/device-name
9. Mount the clone disk’s root (/) file system.
# mount /dev/dsk/device-name /mnt
10. Edit the clone disk’s /etc/vfstab to reference the correct device names.
For example, changing all instances of c0t3d0 with c0t1d0.
11. Unmount the clone disk’s root (/) file system.
# umount /mnt
12. Shut down the system.
# init 0
13. Boot from the clone disk to single-user mode.
Copying UFS Files and File Systems (Tasks)
617
# boot diskn -s
Note - The installboot command is not needed for the clone disk because the
boot blocks are copied as part of the overlap slice.
14. Unconfigure the clone disk.
# sys-unconfig
The system is shut down after it is unconfigured.
15. Boot from the clone disk again and provide its system information, such as
host name, time zone, and so forth.
# boot diskn
16. Log in as superuser to verify the system information after the system is booted.
hostname console login:
Example—Cloning a Disk (dd)
# 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
618
Copying Directories Between File
Systems (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 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.
How to Copy Directories Between File Systems
(cpio)
1. Become superuser.
2. Change to the appropriate directory.
# cd filesystem1
3. 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.
−print
Descends the directory hierarchy and prints file names on the
−depth
way back up.
Creates a list of files.
−p
Copying UFS Files and File Systems (Tasks)
619
Creates directories as needed.
−d
Sets the correct modification times on directories.
−m
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.
4. Verify the copy was successful by displaying the destination directory contents.
# cd filesystem2
# ls
5. If appropriate, remove the source directory.
# rm -rf filesystem1
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.
620
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. 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.
Copying UFS Files and File Systems (Tasks)
621
TABLE 46-3
Advantages and Disadvantages of cpio, pax, and tar Commands
Command
Function
Advantages
Disadvantages
Better portability
pax
Copy files, special files,
See disadvantages for
than the tar or
or file systems that
tar command, except
require multiple tape
cpio commands
that pax can create
for
volumes or when you
multi-tape volumes
want to copy files to
POSIX-compliant
and from
systems
POSIX-compliant
Multi-vendor
systems
support
Available on most
Is not aware of file
tar
Copy files and
UNIX operating
system boundaries
directory subtrees to a
systems
Full pathname
single tape
Public domain
length cannot
versions are readily
exceed 255
available
characters
Does not copy
empty directories
or special files such
as device files
Cannot be used to
create multi-tape
volumes
Packs data onto
cpio
Copy files, special files,
tape more
or file systems that
efficiently than tar
require multiple tape
Skips over any bad
volumes or when you
want to copy files from
spots in a tape
when restoring.
SunOS 5.8 systems to
SunOS 4.0/4.1 systems
Provides options
for writing files
with different
header formats
(tar, ustar, crc,
odc, bar) for
portability between
different system
types
Creates multi-tape
volumes
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 639 for more
information about tape drives and device names.
622
Copying Files to Tape (tar Command)
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.
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.
3.
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.
Indicates that the archive should be written to the
f /dev/rmt/n
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.
4.
Remove the tape from the drive and write the names of the files on the tape
label.
5.
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 624 for more information on listing files on a tar tape.
$ tar tvf /dev/rmt/n
Copying UFS Files and File Systems (Tasks)
623
Example—Copying Files to a Tape (tar)
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
How to List the Files on a Tape (tar)
1. Insert a tape into the tape drive.
2. 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.
Example—Listing the Files on a Tape (tar)
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
624
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. 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.
Displays the name of each file as it is archived.
v
f /dev/rmt/n
Indicates the tape device containing the archive.
filename
Specifies a file to retrieve.
4. Verify the files are copied by listing the contents of the current directory.
$ ls -l
Example—Retrieving the Files on a Tape (tar)
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
Copying UFS Files and File Systems (Tasks)
625
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 624 for instructions.
See tar(1) for more information.
Copying Files to a Tape With pax
This section describes how to copy files with the pax command.
How to Copy Files to a Tape (pax)
1. Change to the directory that contains the files you want to copy.
2. Insert a write-enabled tape into the tape drive.
3. Copy the files to 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.
4. Verify the files are copied to tape.
$ pax -f /dev/rmt/0
5. Remove the tape from the drive and write the names of the files on the tape
label.
626
Example—Copying Files to a Tape (pax)
$ pax -w -f /dev/rmt/0 .
$ pax -f /dev/rmt/0
filea fileb filec
See pax(1) for more information.
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.
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.
3.
Verify the files are copied to tape by using the following cpio command.
$ cpio -civt < /dev/rmt/0
4.
Remove the tape from the drive and write the names of the files on the tape
label.
Example—Copying All Files in a Directory to a Tape (cpio)
The following example copies all of the files in the directory
/export/home/kryten to the tape in tape drive 0.
Copying UFS Files and File Systems (Tasks)
627
$ 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
$
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 an archive tape into the tape drive.
2. List the files on the tape using the cpio command.
$ cpio -civt < /dev/rmt/n
Specifies that cpio should read files in ASCII character
−c
format.
Specifies that cpio should operate in copy-in mode (even
−i
though it’s only listing files at this point).
Displays the output in a format similar to the output from
−v
the ls -l command.
Lists the table of contents for the files on the tape in the tape
−t
drive you specify.
< /dev/rmt/n
Specifies the input file of an existing cpio archive.
628
|
|