Previous Page
Next Page

Solaris Backup and Restoration Utilities

Objective:

Explain how to perform incremental, full, and remote backups to tape for an unmounted file system using the ufsdump command or explain how to back up a mounted file system using UFS snapshot.

Solaris provides the utilities listed in Table 7.3. These backup utilities can be used to copy data from disk to removable media and to restore it.

Table 7.3. Backup Utilities

Utility

Description

tar

Creates tape or file-based archives. This format is commonly used for transferring collections of files between systems.

dd

Converts and copies a file or raw device.

cpio

Copies data from one location to another.

pax

Copies files and directory subtrees to a single tape or file. This utility provides better portability than tar and cpio, so it can be used to transport files to other types of Unix systems.

ufsdump

Backs up all files in a file system.

ufsrestore

Restores some or all of the files archived with the ufsdump command.

zip

Packages and compresses archive files. This utility creates compressed archives that are portable across various platforms, including Unix, VMS, and Windows.

Flash Archive

Combines the use of Jumpstart and backup utilities to provide an easy mechanism for restoring a system to its initial state or cloning systems.

jar

Leverages the portability and flexibility of Java to provide capabilities similar to those of tar, cpio, and zip.


The tar Utility

The primary use of the tar (which stands for tape archiver) command is to copy file systems or individual files between a hard disk and tape or from one file system to another. You can also use tar to create a tar archive on a floppy disk and to extract files from a tar archive on a floppy disk. The tar command is popular because it's available on most Unix systems. If the data you are backing up requires more than one tape, you should use the cpio, pax, or ufsdump commands, which are described in the following sections. The tar command has the following syntax:

tar <options> <tar-filename> <file-list>

You can replace options with the list of command options in Table 7.4.

Table 7.4. Command Options for tar

Option

Description

c

Creates a tar file.

t

Lists the names of the specified files each time they occur in the tar filename. If no file argument is given, the names of all files in the tar file are listed. When t is used with the v function modifier, additional information displays for the specified files. t stands for table of contents.

x

Extracts or restores files from a tar filename.

v

Outputs information to the screen as tar reads or writes the archive. v stands for verbose.

f

Uses the tar filename argument as the name of the tar archive. If f is omitted, tar uses the device indicated by the TAPE environment variable (if it is set). If the TAPE variable is not set, tar uses the default values defined in /etc/default/tar. If the name of the tar file is -, tar writes to the standard output or reads from the standard input.


For a more complete listing of command options, see the Solaris online man pages.

<tar-filename> is used with the f option and can be any name you want. The filename can also be the name of a device, such as /dev/rmt/0 or /dev/rfd0. <file-list> is a list of files you want to include in the archive.

tar Examples

The following examples illustrate the use of the tar command.

To create a tape archive of everything in the /home/bcalkins directory on tape device /dev/rmt/0, you type the following:

tar cvf /dev/rmt/0 /home/bcalkins

To list the files in the archive, you type the following:

tar tvf /dev/rmt/0

To restore the file /home/bcalkins/.profile from the archive, you type the following:

tar xvf /dev/rmt/0 /home/bcalkins/.profile

You use tar to create an archive file on disk instead of tape. The tar filename is files.tar, as follows:

tar cvf files.tar /home/bcalkins

To extract files that were created using the preceding example, you type the following:

tar xvf files.tar

Notice the use of the full pathname when creating an archive with tar. Using the full pathname to create an archive ensures that the files will be restored to their original locations in the directory hierarchy. You will not be able to restore them elsewhere.

If you want to be able to restore files with a relative pathname in the preceding example, you can change to the /home/bcalkins directory and specify files to be archived as ./*. This puts the files into the archive, using a pathname that is relative to the current working directory rather than an absolute pathname (one beginning with a forward slash [/]). Files can then be restored into any directory. The use of relative pathnames is highly recommended so that you have the option of restoring an archive without overwriting files that exist but may be different from those in the archive.

The dd Utility

The main advantage of the dd command is that it quickly converts and copies files with different data formats, such as differences in block size, record length, or byte order.

The most common use of dd is to transfer a complete file system or partition image from a hard disk to a tape. You can also use it to copy files from one hard disk to another. When you're using it to copy data, the dd command makes an image copy (an exact byte-for-byte copy) of any medium, which can be either tape or disk. The syntax for the dd command is as follows:

dd if=<input-file> of=<output-file> <option=value>

The command arguments for dd are described in Table 7.5.

Table 7.5. dd Command Arguments

Argument

Description

if

Designates an input file. The input file can be a filename or a device name, such as /dev/rmt/0. If no input file is specified, input for dd is taken from the standard input.

of

Designates an output file. The output file can be a filename or a device name, such as /dev/rmt/0. If no output file is specified, output from dd is sent to the standard output.

<option=value>

Several other options can be used on the command line to specify buffer sizes, block sizes, and data conversions. See the Solaris online man page dd (1M) for a list of these options.


dd Examples

The next few examples illustrate the use of the dd command to copy data. The first example shows how the dd command is used to duplicate tapes:

dd if=/dev/rmt/0 of=/dev/rmt/1

This procedure requires two tape drivesa source tape and a destination tape.

The next example uses dd to copy one entire hard disk to another hard disk:

dd if=/dev/rdsk/c0t1d0s2 of=/dev/rdsk/c0t4d0s2 bs=128K

In this example, you need two disks, and both must have the same geometry. Disk geometry is discussed in Chapter 1.

Caution

Using dd to Copy Data Between Dissimilar Disk Drives Be careful when using dd to copy data between two different types of disk drives. We have used dd to move data from a 4GB disk to an 18GB disk, and the data transferred fine. We were able to access the data, and the option seemed to have completed correctly. Then we noticed that when we went into the format utility, the 18GB disk was labeled as a 4GB disk. This is because "everything" on the 4GB disk transferred to the 18GB diskincluding the disk label! All of our work was wasted. We had to re-identify the disk type, relabel, and repartition the disk to get it to recognize the disk as an 18GB disk.


In this example, the option bs=128K specifies a block size. A large block size, such as 128KB or 4096KB, can decrease the time to copy by buffering large amounts of data. Notice in the example that the raw device is specified. For this technique to work properly, you must use the raw (character) device to avoid the buffered (block) input/output (I/O) system.

You can use the dd command with tar to create an archive on a remote tape drive. In the next example, tar is used to create an archive on a remote system by piping the output to a tape drive called /dev/rmt/0 on a remote system named xena:

tar cvf - <files> | rsh xena dd of=/dev/rmt/0 obs=128

Another example would be to read tar data coming from another Unix system such as older Silicon Graphics systems. The Silicon Graphics system swaps every pair of bytes, making a tar tape unreadable on a Solaris system. To read a tar tape from a Silicon Graphics system, you type the following:

dd if=/dev/rmt/0 conv=swab | tar xvf -

Note that the argument for the conv option is swab ("swap bytes") and not swap. In a similar way, a Solaris system can create a tar tape that a Silicon Graphics system can read:

tar cvf - <files> | dd of=/dev/rmt/0 conv=swab

The cpio Utility

The cpio command is used to copy data from one place to another. cpio stands for copy input to output. When copying files with cpio, you present a list of files to the system's standard input and write the file archive to the system's standard output. The principal advantage of cpio is its flexible syntax. The command acts as a filter program, taking input information from the standard input file and delivering its output to the standard output file. You can manipulate the input and output by using the shell to specify redirection and pipelines. The following are the advantages of cpio over other Unix utilities:

  • cpio can back up and restore individual files, not just whole file systems. (tar, pax, and ufsdump also have this capability.)

  • Backups made by cpio are slightly smaller than those created with tar because the cpio header is smaller.

  • cpio can span multiple tapes; tar is limited to a single tape.

cpio has more options and is therefore perceived as a more complex command than tar.

The cpio utility operates in one of three modes: copy out (cpio -o), copy in (cpio -i), or pass (cpio -p). You use copy-out mode when creating a backup tape and copy-in mode when restoring or listing files from a tape. The pass mode is generally used to copy files from one location to another on disk. You must always specify one of these three modes. The command syntax for the cpio command is as follows:

cpio <mode> <option>

mode is -i, -o, or -p, and option is one of the options described in Table 7.6.

Table 7.6. Command Options for cpio

Option

Description

-c

Writes header information in ASCII format for portability.

-d

Creates directories as needed.

-B

Specifies that the input has a blocking factor of 5,120-byte records instead of the default 512-byte records. You must use the same blocking factor when you retrieve or copy files from the tape to the hard disk as you did when you copied files from the hard disk to the tape. You must use the -B option whenever you copy files or file systems to or from a tape drive.

-v

Reports the names of the files as they are processed. -v stands for verbose.

-u

Copies unconditionally. Without this option, an older file will not replace a newer file that has the same name.

-m

Retains the previous file modification time. This option is ineffective on directories that are being copied.

-P

With output, causes existing access control lists (ACLs) to be written along with other attributes, except for extended attributes, to the standard output. With input, causes existing ACLs to be extracted along with other attributes from standard input. -P stands for preserve ACLs.


cpio Examples

The following example shows how to copy the directory /work and its subdirectories to a tape drive with the device name /dev/rmt/0:

cd /work
-find . | cpio -ocB > /dev/rmt/0

In this example, the find command locates all of the files in the current working directory and pipes them to the cpio command. The -o option specifies copy-out mode, -c outputs the header information in ASCII format, and -B increases the blocking factor to 5,120 bytes to improve the speed.

The following example shows how to copy the files located on a tape back into the directory named /work on a hard disk:

cd /work
cpio -icvdB < /dev/rmt/0

The -i option specifies copy-in mode, -d creates directories as needed to restore the data to the original location, and -v displays all the output.

Backing Up Files with Copy-Out Mode

To use copy-out mode to make backups, you send a list of files to the cpio command via the standard input of cpio. You use the Unix find command to generate the list of files to be backed up. You specify copy-out mode by using the -o option on the cpio command line. In the following example, a file named list contains a short list of files to be backed up to tape:

cpio -ovB < list > /dev/rmt/1

Normally, as indicated in Table 7.6, cpio writes files to the standard output in 512-byte records. By specifying the -B option, you can increase the record size to 5,120 bytes to significantly speed up the transfer rate, as shown in the previous example. You can use Unix commands to generate a list of files for cpio to back up in a number of other ways, as shown in the following examples.

You can back up files by entering filenames via the keyboard. You press Ctrl+D when you have finished typing filenames. For example, enter the following:

cpio -oB > /dev/rmt/1
File1.txt
File2.txt
Ctrl+d

You can use the ls command to generate the list of files to be backed up by cpio. You type the following to back up all the files in the current directory but not the files in subdirectories:

cd /home/bcalkins
ls -d * | cpio -oB >/dev/rmt/1

You need to be careful when using ls to generate the list of files to back up. In particular, you should be sure that the ls command specifies the full path to the files that should be backed up. You will be dissatisfied with the results if you try to use ls -R or any other ls command on a directory unless you specify the -d option to ls.

In general, the best command to use for generating a file list is find. You can use the find command to generate a list of files that the user bcalkins created and modified in the past five days. The following is the list of files to be backed up:

find . -user bcalkins -mtime -5  -print | cpio -oB > /dev/rmt/1

If the current tape fills up, the cpio program prompts you for another tape. You see a message such as the following:

If you want to go on, type device/file name when ready

You should then change the tape and enter the name of the backup device (for example, /dev/rmt/1).

Restoring Files with Copy-In Mode

You use the copy-in mode of cpio to restore files from tape to disk. The following examples describe methods used to restore files from a cpio archive.

The following example restores all files and directories from tape to disk:

cd /users
cpio -icvumB < /dev/rmt/1

The cpio options specified restore files unconditionally (-u) to the /users directory and retain previous file modification times (-m).

The following example selectively restores files that begin with database:

cpio -icvdumB 'database*' < /dev/rmt/1

The -d option in this example creates directories as needed.

Note

Using Wildcards with cpio You must use standard shell escapes to pass the wildcard argument (*) to cpio. For example, the wildcard argument can appear within single quotes.


To obtain a list of files that are on tape, you use the following code:

cpio -ictB < /dev/rmt/1

The list of files on /dev/rmt/1 then appears onscreen.

Using Pass Mode

Pass mode is generally not used for backups. The destination must be a directory on a mounted file system, which means that pass mode cannot be used to transfer files to tape. However, you can use pass mode to copy files from one directory to another. The advantage of using cpio over cp is that with it, original modification times and ownership are preserved. You specify pass mode by using the -p option with cpio.

The following example copies all files from /users to /bkup:

cd /users
mkdir /bkup
find .  | cpio -pdumv /bkup

Files are listed onscreen as they are copied.

The pax Utility

The pax command has been included in Solaris since version 2.5. pax is a POSIX-conformant archive utility that can read and write tar and cpio archives. It is available on all Unix systems that are POSIX compliant, such as IBM's AIX, Hewlett-Packard's HP-UX, and some Linux distributions.

pax can read, write, and list the members of an archive file and copy directory hierarchies. The pax utility supports a wide variety of archive formats, including tar and cpio.

If pax finds an archive that is damaged or corrupted while it is processing, pax attempts to recover from media defects. It searches the archive to locate and process the largest possible number of archive members.

The action to be taken depends on the presence of the -r and -w options, which together form the four modes of operation: list, read, write, and copy (as described in Table 7.7). The syntax for the pax command is as follows:

pax <mode> <options>

Table 7.7. Four Modes of Operation for pax

Option

Operation Mode

Description

-r

Read mode

When -r is specified but -w is not, pax extracts the filenames and directories found in the archive file. The archive file is read from disk or tape. If an extracted file is a directory, the file hierarchy is extracted as well. The extracted files are created relative to the current file hierarchy.

None

List mode

When neither -r nor -w is specified, pax displays the filenames or directories found in the archive file. The archive file is read from disk, tape, or the standard input. The list is written to the standard output.

-w

Write mode

When -w is specified but -r is not, pax writes the contents of the file to the standard output in an archive format specified by the -x option. If no files are specified, a list of files to copy (one per line) is read from the standard input. A directory includes all the files in the file hierarchy whose root is at the file.

-rw

Copy mode

When both -r and -w are specified, pax copies the specified files to the destination directory.


In addition to selecting a mode of operation, you can select one or more options to pax from Table 7.8.

Table 7.8. Command Options for pax

Option

Description

-r

Reads an archive file from the standard input and extracts the specified files. If any intermediate directories are needed to extract an archive member, these directories are created.

-w

Writes files to the standard output in the specified archive format. When no file operands are specified, the standard input is read for a list of pathnamesone per line, without leading or trailing blanks.

-a

Appends files to the end of an archive that was previously written.

-b

Specifies the block size, which must be a multiple of 512 bytes with a maximum of 32,256 bytes. A block size can end with k or b to specify multiplication by 1,024 bytes (1KB) or 512 bytes, respectively. -b stands for block size.

-c

Matches all file or archive members except those specified by the pattern and file operands.

-f <archive>

Specifies <archive> as the pathname of the input or output archive. A single archive can span multiple files and different archive devices. When required, pax prompts for the pathname of the file or device in the next volume in the archive.

-i

Interactively renames files or archive members. For each archive member that matches a pattern operand or file that matches a file operand, a prompt is written to the terminal.

-n

Selects the first archive member that matches each pattern operand. No more than one archive member is matched for each pattern.

-p <string>

Specifies one or more file-characteristic options (privileges). string is a string that specifies file characteristics to be retained or discarded when the file is extracted. The string consists of the specification characters a, e, m, o, p, and v. Multiple characteristics can be concatenated within the same string, and multiple p options can be specified. The meanings of the specification characters are as follows:

a Does not preserve file access times

e Preserves everything: user ID, group ID, file mode bits, file access times, and file modification times

m Does not preserve file modification times

o Preserves the user ID and group ID

p Preserves the file mode bits

v Specifies verbose mode

-x <format>

Specifies the output archive format, with the default format being ustar. pax currently supports cpio, tar, bcpio, ustar, sv4crc, and sv4cpio.


For additional options to the pax command, see the Solaris man pages.

When you use pax, you can specify the file operand along with the options from Table 7.7. The file operand specifies a destination directory or file pathname. If you specify a directory operand that does not exist, that the user cannot write to, or that is not of type directory, pax exits with a nonzero exit status.

The file operand specifies the pathname of a file to be copied or archived. When the file operand does not select at least one archive member, pax writes the file operand pathnames in a diagnostic message to standard error and then exits with a nonzero exit status.

Another operand is the pattern operand, which is used to select one or more pathnames of archive members. Archive members are selected by using the filename pattern-matching notation described by fnmatch. The following are examples of pattern operands:

pattern Operand

Description

?

Matches any character

*

Matches multiple characters

[

Introduces a pattern bracket expression


When a pattern operand is not supplied, all members of the archive are selected. When a pattern operand matches a directory, the entire file hierarchy rooted at that directory is selected. When a pattern operand does not select at least one archive member, pax writes the pattern operand pathnames in a diagnostic message to standard error, and then exits with a nonzero exit status.

pax Examples

The following examples illustrate the use of the pax command.

To copy files to tape, you issue the following pax command, using -w to copy the current directory contents to tape and -f to specify the tape device:

pax -w -f /dev/rmt/0

To list a verbose table of contents for an archive stored on tape device /dev/rmt/0, you issue the following command:

pax -v -f /dev/rmt/0

The tape device in these two examples could have been a filename to specify an archive on disk.

You use the following command to interactively select the files to copy from the current directory to the destination directory:

pax -rw -i . <dest-dir>

Because pax understands tar and cpio formats, it is a very helpful tool when a tar or cpio archive contains absolute pathnames and the files should not be restored to their original locations. The key is the -s option, which allows files to be programmatically renamed. The following example uses the -s option to extract files from a tar archive, stripping the leading slash from any absolute pathname:

pax -r -s ',^/,,' -f file.tar

As you become more familiar with the pax utility, you might begin to use it in place of tar and cpio for the following reasons:

  • It is portable to other Unix systems.

  • It is capable of recovering damaged archives.

  • It is capable of spanning multiple volumes.

The ufsdump Utility

Objective:

Explain how to perform incremental, full, and remote backups to tape for an unmounted file system using the ufsdump command, or explain how to back up a mounted file system using UFS snapshot.

Given a backup requirement, develop a backup strategy that includes scheduled backups, number of tapes required, naming conventions, command protocols, and backup frequency/levels.

Whereas the other Solaris utilities discussed in this chapter can be used to copy files from disk to tape, ufsdump is designed specifically for backups and is the recommended utility for backing up entire Solaris file systems. The ufsdump command copies files, directories, or entire file systems from a hard disk to tape or from disk to disk. The only drawback of using ufsdump is that the file systems must be inactive (that is, unmounted or read-only) before you can conduct a full backup. If the file system is still active, nothing in the memory buffers is copied to tape, and you could end up with a corrupt backup.

You should back up any file systems that are critical to users, including file systems that change frequently. Table 7.9 gives suggestions on the file systems to back up and the suggested frequency.

Table 7.9. File Systems to Back Up

File System

Frequency

root (/)

If you frequently add and remove clients and hardware on the network or you have to change important files in root (/), this file system should be backed up. You should do a full backup of the root file system between once a week and once a month. If /var is in the root file system and your site keeps user mail in the /var/mail directory on a mail server, you might want to back up root daily.

/usr

The contents of this file system are fairly static and need to be backed up only between once a week and once a monthand after new software or patches are installed.

/export/home

The /export/home file system usually contains the home directories and subdirectories of all users on the system; its files are volatile and should be backed up daily.


The ufsdump command has many built-in features that the other archive utilities don't have, including the following:

  • The ufsdump command can be used to back up individual file systems to local or remote tape devices or disk drives. The device to which the files are being backed up can be on any system in the network. This command works quickly because it is aware of the structure of the Unix file system and it works directly through the raw device file.

  • ufsdump has built-in options to create incremental backups that back up only the files that have been changed since a previous backup. This saves tape space and time.

  • ufsdump has the capability to back up groups of systems over the network from a single system. You can run ufsdump on each remote system through a remote shell or remote login, and you can direct the output to the system on which the drive is located.

  • With ufsdump, the system administrator can restrict user access to backup tables.

  • The ufsdump command has a built-in option to verify data on tape against the source file system.

Backing up a file system with ufsdump is referred to as dumping a file system. When a file system is dumped, a level between 0 and 9 is specified. A level 0 dump is a full backup and contains everything on the file system. Levels 1 through 9 are incremental backups and contain only files that have changed since previous dumps at lower levels.

A recommended backup schedule involves a three-level dump strategy: a level 0 dump at the start of the month (manually), automated weekly level 5 dumps, and automated daily level 9 dumps. The automated dumps are performed at 4:30 a.m., for examplea time when most systems are typically idle. Automated daily dumps are performed Sunday through Friday mornings. Automated weekly dumps are performed on Saturday mornings. Backups are automated by creating a shell script and using cron to execute the script on a regular basis.

Table 7.10 shows the dump level performed on each day of a typical month. Note that the level 0 dump at the start of the month is performed manually because the entire system must be idle before you can back up the root file system. One way to ensure that the system is not being used is to put the system in single-user mode. The level 9 and 5 dumps are automated with cron, but also must be conducted when the file systems are not being used. See Chapter 5, "Managing System Processes," for more information on cron.

Table 7.10. File System Dump Schedule

Floating

Sun

Mon

Tues

Wed

Thurs

Fri

Sat

1st of month

0

      

Week 1

9

9

9

9

9

9

5

Week 2

9

9

9

9

9

9

5

Week 3

9

9

9

9

9

9

5

Week 4

9

9

9

9

9

9

5


The backup schedule in Table 7.10 accomplishes the following:

  • Each weekday tape accumulates all files changed since the end of the previous week or the initial level 0 backup for the first week. All files that have changed since the lower-level backup at the end of the previous week are saved each day.

  • Each Saturday tape contains all files changed since the last level 0 backup.

This dump schedule requires at least four sets of seven tapesone set for each week and one tape for the level 0 dump. Each set will be rotated each month. The level 0 tapes should not be overwritten and should be saved for at least a year, depending on your company's and jurisdiction's data-retention policy.

Even with the backup schedule outlined in Table 7.10, data can still be lost. For example, if a hard disk fails at 3 p.m., all modifications since the preceding 4:30 a.m. backup will be lost. Also, files that were deleted midweek will not appear on the level 5 tapes. Or a user may accidentally delete a file and not realize it for several weeks, but when the user wants to use the file, it is not there. If he asks you to restore the file from backup, the only tape it appears on is the level 0 backup, and it could be too far out of date to be useful. By not overwriting the daily level 9 tapes frequently, you can minimize this problem.

The syntax for the ufsdump command is as follows:

/usr/sbin/ufsdump  <options>  <arguments>  <files-to-dump>

The options to the ufsdump command are described in Table 7.11.

Table 7.11. ufsdump Command Options

Option

Description

<options>

A single string of one-letter option names.

<arguments>

The argument that goes with each option. The option letters and the arguments that go with them must be entered in the same order.

<files-to-dump>

The files to back up. This argument must always come last. It specifies the source or contents of the backup. It usually identifies a file system, but it can also identify individual files or directories. For a file system, you specify the name of the file system or the raw device file for the disk slice where the file system is located.


Table 7.12 describes the options and arguments for the ufsdump command.

Table 7.12. Options for the ufsdump Command

Option

Description

0 to 9

Specifies the backup level. Level 0 is for a full backup of the entire file system. Levels 1 through 9 are for incremental backups of files that have changed since the last lower-level backup.

a <archive-file>

Instructs ufsdump to create an archive file. Stores a backup table of the tape contents in a specified file on the disk. The file can be understood only by ufsrestore, which uses the table to determine whether a file to be restored is present in a backup file and, if so, on which volume of the medium it resides.

b <factor>

Specifies the blocking factor: the number of 512-byte blocks to write to tape per operation.

c

Instructs ufsdump to back up to cartridge tape. When end-of-media detection applies, this option sets the block size to 126.

d <bpi>

Specifies the tape density. You should use this option only when ufsdump cannot detect the end of the medium.

D

Backs up to floppy disk.

f <dump-file>

Specifies the destination of the backup. <dump-file> can be one of the following:

A local tape drive or disk drive

A remote tape drive or disk drive

Standard output

 

You use this argument when the destination is not the default local tape drive /dev/rmt/0. If you use the f option, you must specify a value for dump-file.

l

Specifies autoload. You 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 the drive is not ready after two minutes, autoload prompts the operator to load another tape.

n

Specifies notify. When intervention is needed, this option sends a message to all terminals of all users in the sys group.

o

Specifies offline. When ufsdump is finished with a tape or disk, it takes the drive offline, rewinds it (if it's a tape), and removes the medium, if possible. (For example, it ejects a disk or removes an 8mm autoloaded tape.)

s <size>

Specifies the length of tape, in feet, or the size of the disk, in the number of 1,024-byte blocks. You need to use this option only when ufsdump cannot detect the end of the medium.

S

Estimates the size of the backup. This option determines the amount of space needed to perform the backup (without actually doing it) and outputs a single number that indicates the estimated size of the backup, in bytes.

t <tracks>

Specifies 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 medium.

u

Updates the dump record. For a completed backup of a file system, this option adds an entry to the file /etc/dumpdates. The entry indicates the device name for the file system's disk slice, the backup level (0 to 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

Verifies the contents of the medium against the source file system after each tape or disk is written. If any discrepancies appear, this option prompts the operator to mount a new medium and then repeats the process. You use this option on an unmounted or snapshot file system only; any activity in the file system causes it to report discrepancies.

w

Lists 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

Shows all file systems that appear in /etc/dumpdates and highlights file systems that have not been backed up within a day. When you use this option, all other options are ignored.


The ufsdump command uses these options by default:

ufsdump 9uf /dev/rmt/0 <files-to-back-up>

ufsdump Examples

The following examples illustrate the use of the ufsdump command.

The following is an example of a full backup of the /users file system:

ufsdump 0ucf /dev/rmt/0 /users
  DUMP: Writing 63 Kilobyte records
  DUMP: Date of this level 0 dump: Thu Jul 25 10:43:25 2002
  DUMP: Date of last level 0 dump: the epoch
  DUMP: Dumping /dev/rdsk/c0t1d0s0 (pyramid1:/users) to /dev/rmt/0.
  DUMP: Mapping (Pass I) [regular files]
  DUMP: Mapping (Pass II) [directories]
  DUMP: Estimated 10168 blocks (4.96MB).
  DUMP: Dumping (Pass III) [directories]
  DUMP: Dumping (Pass IV) [regular files]
  DUMP: Tape rewinding
  DUMP: 10078 blocks (4.92MB) on 1 volume at 107 KB/sec
  DUMP: DUMP IS DONE

If you want to see how much space a backup is going to require, you issue the following command:

ufsdump S <filesystem>

The estimated number of bytes needed on tape to perform the level 0 backup is displayed.

In the following example, the local /export/home file system on a Solaris 10 system is backed up to a tape device on a remote Solaris 10 system called sparc1:

ufsdump 0ucf sparc1:/dev/rmt/0 /export/home
DUMP: Date of this level 0 dump: Thu Jul 25 10:43:25 2002
DUMP: Date of last level 0 dump: the epoch
DUMP: Dumping /dev/rdsk/c0t3d0s7 (/export/home) to /dev/rmt/0 \
 on host sparc1
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 19574 blocks (9.56MB)
DUMP: Writing 63 Kilobyte records
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: level 0 dump on Thu Jul 25 10:43:25 2002
DUMP: Tape rewinding
DUMP: 19574 blocks (9.56MB) on 1 volume
DUMP: DUMP IS DONE

In this example, the -u option is used with the ufsdump command. This causes ufsdump to make an entry into the /etc/dumpdates file, which records the file system that was backed up, the level of the last backup, and the day, date, and time of the backup. Here's an example of looking into the /etc/dumpdates file:

more /etc/dumpdates

The system responds with the following:

/dev/rdsk/c0t0d0s7           0 Mon Mar 25 10:47:46 2005
/dev/rdsk/c0t0d0s6           0 Mon Mar 25 10:48:04 2005

When incremental backups are made by using ufsdump, the ufsdump command consults the /etc/dumpdates file to find the date of the most recent backup at the next lower level. ufsdump then copies all files modified or added since the date of that lower-level backup. You can also determine whether backups are being done by viewing the contents of the /etc/dumpdates file. If a backup fails, it is not recorded in /etc/dumpdates.

Another useful example is using ufsdump to copy the contents of one file system to another. In the section "The dd Utility," you learned how to copy data from one disk to another, but only when the disk geometry is exactly the same for each disk. In other words, dd works when you want to copy a 4GB disk to another 4GB disk. But if you want to replace an older 4GB disk with a new 18GB disk, you should not use dd to copy the data; a better option is to use ufsdump. Moving data from disk to tape and then back to disk again can be time consuming. Here's a way to move data directly to that file system by using ufsdump without going to tape:

ufsdump 0f - /export/home | (cd /data; ufsrestore  -xf - )

In this example, all data in the /export/home file system is copied to the /data file system. Instead of specifying a tape device, this example specifies a - (hyphen). The hyphen dumps the data to standard output and restores the data from standard input rather than from a file or device. This creates and extracts the dump file in memory, speeding up the entire process.

The ufsrestore Utility

Objective:

Explain how to perform UFS restores and special case recoveries.

Tip

Restoring File Systems You need to understand each step described in Step by Step 7.1 and Step by Step 7.2, along with the order in which each step is performed. Also, you need to understand what the restoresymtable file is used for. These topics are likely to be on the exam.


The ufsrestore command copies files from backups created using the ufsdump command. As root, you can use ufsrestore to reload an entire file system from a level 0 dump and any incremental dumps that follow it, or to restore one or more single files from any dump tape. ufsrestore restores files with their original owner, last modification time, and mode (permissions).

The syntax for the ufsrestore command is as follows:

ufsrestore  <options>  <arguments> <filename(s)>

The options for the ufsrestore command are described in Table 7.13.

Table 7.13. ufsrestore Command Options

Option

Description

<options>

Gives you the choice of one and only one of these options: i, r, R, t, or x

<arguments>

Follows the <options> string with the arguments that match the options

<filename(s)>

Specifies files to be restored as arguments to the x or t options and must always come last


Table 7.14 describes some of the most common options and arguments for the ufsrestore command.

Table 7.14. Command Options for the ufsrestore Command

Option

Description

i

Runs ufsrestore in interactive mode. In this mode, you can use a limited set of shell commands to browse the contents of the medium and select individual files or directories to restore. See Table 7.15 for a list of available commands.

r

Restores the entire contents of the medium 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 is also included. To completely restore a file system, you use this option to restore the full (level 0) dump and then each incremental dump. This is intended for a new file system that was just created with the newfs command. r stands for recursive.

x <filename(s)>

Selectively restores the files you specify, using the <filename(s)> argument. <filename(s)> 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(s)> or enter . for the root directory, all files on all volumes of the medium (or from standard input) are restored. Existing files are overwritten, and warnings are displayed. x stands for extract.

t <filename(s)>

Checks the files specified in the <filename(s)> argument against the medium. For each file, the full filename and the inode number (if the file is found) are listed. If the filename is not found, ufsrestore indicates that the file is not on the volume, meaning any volume in a multivolume dump. If you do not enter the <filename(s)> argument, all files on all volumes of the medium are listed, without distinction as to the volume on which the files are located. When you use the h option, only the directory files specified in <filename(s)>not their contentsare checked and listed. The table of contents is read from the first volume of the medium or (if you use the a option) from the specified archive file. This option is mutually exclusive with the x and r options.

b <factor>

Specifies the number of 512-byte blocks to read from tape per operation. By default, ufsrestore tries to figure out the block size used in writing the tape. b stands for blocking factor.

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 numbers. For example, if the current working directory is /files, a file in the backup named ./database/test with inode number 156 is restored as /files/156. This option is useful when you are extracting only a few files.

s<n>

Skips to the nth backup file on the medium. This option is useful when you put more than one backup on a single tape.

v

Displays the name and inode number of each file as it is restored. v stands for verbose.


For a full listing of options for the ufsrestore command, see the Solaris man pages.

Table 7.15 lists the commands that can be used with ufsrestore when you're using interactive mode (that is, ufsrestore -i).

Table 7.15. Commands for Interactive Restoration

Command

Description

ls <directory-name>

Lists the contents of either the current directory or the specified directory. Directories are suffixed with a forward slash (/). Entries in the current list to be restored (extracted) are marked by an asterisk (*) prefix. If the v option is in effect, inode numbers are also listed.

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. Note that it's possible that not all the files you want to restore to a directory will be on a single backup tape or disk. You might need to restore from multiple backups at different levels to get 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. Note that the files and directories are deleted only from the extract list you are building. They are not deleted from the medium.

extract

Extracts the files in the list and restores them to the current working directory on the disk. You should specify 1 when asked for a volume number. If you are doing a multitape or multidisk restoration and are restoring a small number of files, you should start with the last tape or disk.

help

Displays a list of the commands you can use in interactive mode.

pwd

Displays the pathname of the current working directory in the backup hierarchy.

q

Quits interactive mode without restoring additional files.

verbose

Turns the verbose option on or off. You can also enter verbose mode by entering v on the command line outside interactive mode. When verbose is on, the interactive ls command lists inode numbers, and the ufsrestore command displays information about each file as it is extracted.


ufsrestore Examples

The following examples illustrate how to restore data from a tape by using ufsrestore.

You can use the ufsrestore command to display the contents of a tape:

ufsrestore tf /dev/rmt/0
    2      .
 4249      ./users
12400      ./users/bill
12401      ./users/bill/.login
12402      ./users/bill/.cshrc
12458      ./users/bill/admin
12459      ./users/bill/junk

You can use ufsrestore to restore a file from a backup that was created using ufsdump:

ufsrestore f /dev/rmt/0 filename

You can restore entire directories from a remote drive located on the system called sparc1 by adding sparc1: to the front of the tape device name, as illustrated in the following example:

ufsrestore rf sparc1:/dev/rmt/0 filename

Occasionally, a file system becomes so damaged that you must completely restore it from a backup. If you have faithfully backed up file systems, you can restore them to the state of the last backup. The first step in recovering a file system is to delete everything in the damaged file system and re-create the file system by using the newfs command. To recover a damaged file system, follow the procedure described in Step by Step 7.1.

Step By Step 7.1: Recovering and Restoring a Damaged File System

1.
Unmount the corrupted file system /<filesystem>:

umount  /<filesystem>

2.
After you unmount the file system, issue the newfs command to create a new file system:

newfs /dev/rdsk/<disk-partition-name>

<disk-partition-name> is the name of the raw disk partition that contains the corrupted file system. Make sure you are using the correct device name; otherwise, you might destroy another file system.

3.
Mount the file system to be restored and change to that directory:

mount /dev/dsk/<c?t?d?s?> <directory>
cd /<directory>

4.
Load the tape and issue the following command:

ufsrestore rf /dev/rmt/0

The entire content of the tape is restored to the file system. All permissions, ownerships, and dates remain as they were when the last incremental tape was created.

The next two steps are optional.

5.
Remove the restoresymtable file created by the ufsrestore command. This is a temporary file that is created whenever you restore an entire file system from tape. The restoresymtable file is used only by ufsrestore for "check-pointing" when information is passed between incremental restorations. The restoresymtable file is not required after the file system has been successfully restored.

6.
Unmount the file system and run fsck again to check the repaired file system.


Recovering the Root (/) or /usr File System

Sometimes a careless administrator with root access accidentally deletes part or all of the root or /usr file system. Other times the file system can become unusable because of a faulty disk drive or a corrupted file system. You can follow the procedure described in Step by Step 7.2 if you ever need to recover the root or /usr file system.

Step By Step 7.2: Recovering the Root or /usr File System

1.
Replace and partition the disk if it has failed.

2.
Because the system cannot be booted from the boot disk, boot from the CD-ROM and re-create the failed file system by issuing the newfs command:

newfs /dev/rdsk/<disk-partition-name>

<disk-partition-name> is the name of the raw disk partition that contains the corrupted file system.

3.
Check the new file system by using fsck:

fsck /dev/rdsk/<disk-partiton-name>

4.
Mount the new file system on a temporary mount point:

mount /dev/dsk/<disk-partition-name>/mnt

5.
Change to the /mnt directory:

cd /mnt

6.
Write protect the tapes so that you don't accidentally overwrite them.

7.
Load the tape and issue the following command:

ufsrestore rf /dev/rmt/0

The entire content of the tape is restored to the file system. All permissions, ownerships, and dates remain as they were when the last incremental tape was created.

8.
Verify that the file system is restored:

ls

9.
Remove the restoresymtable file that is created and used by ufsrestore to checkpoint the restoration:

rm restoresymtable

10.
Change to the root (/) directory:

cd /

11.
Unmount the newly created file system:

umount /mnt

12.
Check the new file system with fsck:

fsck /dev/rdsk/<disk-partition-name>

The restored file system is checked for consistency.

13.
If you are recovering the root (/) file system, create the boot blocks on the root partition by using the installboot command:

installboot  /usr/platform/'uname-I'/lib/fs/ufs/bootblk\
 /dev/rdsk/<disk-partition-name>

The installboot command installs the boot blocks onto the boot disk. Without the boot blocks, the disk cannot boot.

14.
Insert a new tape into the tape drive and back up the new file system:

ufsdump 0uf /dev/rmt/n /dev/rdsk/<device-name>

A level 0 backup is performed. You should immediately make a backup of a newly created file system because ufsrestore repositions the files and changes the inode allocation.

15.
Reboot the system with a reconfiguration reboot:

# shutdown -y -g0 -i0
ok boot -r

The system is rebooted.


The following example is an actual session that restores the root (/) file system from tape device /dev/rmt/0 to Small Computer System Interface (SCSI) disk target 3, slice 0, on controller 0:

# mount /dev/dsk/c0t3d0s0 /mnt
# cd /mnt
# devfsadm -c tape
# ufsrestore rf /dev/rmt/0

Note

devfsadm The devfsadm command with the -c tape option creates the /dev entries for the tape drive only. It creates links in /dev/rmt to the actual tape device special files. The devfsadm command is covered in Chapter 1.


Files are restored from tape. When this is complete, you are returned to a shell prompt. You can then remove the restoresymtable file, unmount the file system, and use fsck on the device:

# rm restoresymtable
# cd /
# umount /mnt
# fsck /dev/rdsk/c0t3d0s0

The system displays the fsck passes as the file system is checked:

# installboot
 /usr/platform/'uname -i'/lib/fs/ufs/bootblk /dev/rdsk/c0t3d0s0
# ufsdump 0uf /dev/rmt/0 /dev/rdsk/c0t3d0s0
# shutdown -y -g0 -i0

The system is halted. At the ok prompt, you perform a reconfiguration reboot as follows:

boot -r

Performing a reconfiguration reboot ensures that all devices connected to the system have been configured properly in the kernel and in the /dev and /devices directories.

Additional Notes About Restoring Files

When you restore files in a directory other than the root directory of the file system, ufsrestore re-creates the file hierarchy in the current directory. For example, if you restore to /home files that were backed up from /users/bcalkins/files, the files are restored in the directory /home/users/bcalkins/files.

When you restore individual files and directories, it's a good idea to restore them to a temporary directory such as /var/tmp. After you verify that you've retrieved the correct files, you can move them to their proper locations. You can restore individual files and directories to their original locations; however, if you do so, you should be sure that you do not overwrite newer files with older versions from the backup tape.

You should not forget to make regular backups of your operating system. Losing all the customization you dosuch as adding user accounts, setting up printers, and installing application softwarewould be disastrous. Whenever you make modifications that affect the root (/),/usr, /opt, or other operating system directories, you should bring down the system into single-user mode and perform a level 0 dump.


Previous Page
Next Page