File System Administration
  Buscar sólo este libro
Descargar este libro en PDF

Restoring Files and File Systems

8

This chapter has these sections:
Preparing to Restore Files and File Systemspage 139
Restoring Complete File Systemspage 142
Restoring Individual Files and Directoriespage 146
Using a Remote Drive to Restore Filespage 150
Troubleshootingpage 150
Options and Arguments for the ufsrestore Commandpage 151
This chapter describes how to use the ufsrestore(1M) command to restore files and file systems that were backed up using the ufsdump command. See Chapter 4, "Copying UFS Files and File Systems," for information about other commands you can use to archive, restore, copy, or move files and file systems.

Preparing to Restore Files and File Systems

The ufsrestore command copies files from backups created using the ufsdump command into the current working directory. You can use ufsrestore to reload an entire file system hierarchy from a level 0 dump and incremental dumps that follow it or to restore one or more single files from any dump tape. If ufsrestore is run by root, files are restored with their original owner, last modification time, and mode (permissions).
Before you start to restore files or file systems, you need to know:
  • Which tapes (or diskettes) you need
  • The raw device name for the file systems you want to back up
  • The type of tape drive you will use
  • The device name (local or remote) for the tape drive
This section describes how to find this information.

Determining Which Tapes to Use

Before you can begin restoring file systems or files, you must determine which backup tapes you need.
· How to Determine Which Tapes to Use for a Complete or Incremental Restore
When restoring an entire file system, you always need the most recent level 0 backup tape. You also need the most recent incremental backup tapes made at each of the higher levels. Refer to the backup plan that you are using to determine the levels and number of tapes you need. See "Planning a Backup Schedule" on page 112 for more information.
For example, if you make level 0 and level 9 backups, you need the most recent level 0 backup tape and the last level 9 backup tape made.
· How to Determine Which Tapes to Use to Restore Individual Files or File Systems
  1. Ask the user the date when the file or file system was lost, or the approximate date of the files to be recovered.

  2. Refer to your backup plan to find the date of the last backup that would have the file or file system on it.

    Note that you do not necessarily use the most recently backed up version of the file. To retrieve the most recent version of a file, work backward through the incremental backups from highest to lowest level and most recent to least recent.

  1. If you have online archive files, type ufsrestore ta archive-name ./path/filename(s) and press Return.

    Be sure to use the complete path for the filename(s). A list of the files and the media they are stored on is displayed.

  2. Retrieve the media containing the backups.

    Be aware of the storage organization of backup media at your site, so that you can locate media that are months or years old.

  3. [Optional] Insert media in the drive and type.

    ufsrestore tf device-name ./path/filename(s) and press Return. Be sure to use the complete path for the filename(s). If a file is in the backup, its name and inode number is listed. Otherwise, a message says it is not on the volume.

  4. If you have multiple dump files on the same tape, you can use the -s n option to position the tape at the dump you want to use. For example, type ufsrestore xfs /dev/rmt0 5 and press Return to position the tape at the fifth dump and restore it.

Example: How to List Files from an OnLine Archive or Backup Tape If you use ufsdump to dump the /usr slice, the table of contents lists only the files and directories under /usr. To see if /usr/bin/pwd is in the online archive, type:

  # ufsrestore ta archive-name ./bin/pwd  

To see if /usr/bin/pwd is on the backup tape, type:

  # ufsrestore tf /dev/rmt0 ./bin/pwd  

Determining the Disk Device Name

If you have properly labeled your backup tapes, you should be able to use the disk device name (/dev/rdsk/cntndnsn) from the tape label. See "How to Find File System Raw Device Names" on page 122 for more information.

Determining the Type of Tape Drive You Will Use

You must use a tape drive that is compatible with the backup media to restore the files. The format of the backup media determines which drive you must use to restore files. For example, if your backup media is 8-mm tape, you must use an 8-mm tape drive to restore the files.

Determining the Tape Device Name

You may have specified the tape device name (/dev/rmt/unit) as part of the backup tape label information. If you are using the same drive to restore a backup tape, you can use the device name from the label. See "Choosing Which Media to Use" on page 102 for more information on media devices and device names.

Restoring Complete File Systems

Occasionally, a file system becomes so damaged that you must completely restore it. Typically, you need to restore a complete file system because of a disk head crash. You may need to replace the hardware before you can restore the software. See Peripherals Administration for information on how to replace a disk. Fully restoring a file system such as /export/home can take a lot of time. If you have faithfully backed up file systems, you can restore them to their state as of the last incremental backup.

Synopsis of Steps

This section provides an overview of a good strategy for restoring complete file systems:
  1. Replace any broken hardware.

  2. If replacing a disk:

    a. Add the defect list and be sure the defect list is found.

    b. Format the disk.

    c. Re-create the slices to match the old slices. d. Label the disk.

e. Remake the file systems.
f. Check that the file system was properly remade.
  1. Mount the file system on a temporary mount point.

  2. Restore the contents of the latest full backup, and then restore subsequent incremental backups from lowest to highest level.

  3. Unmount the file system from its temporary mount point.

  4. Check the file system for inconsistencies.

  5. Mount the file system at its permanent mount point.

· How to Restore a Complete File System (not / or /usr)
  1. Become superuser.

  2. If necessary, type umount /dev/rdsk/cntndnsn and press Return.

  3. Type newfs /dev/rdsk/cntndnsn and press Return. You are asked if you want to construct a new file system on the device.

  4. Type y and press Return.

    The new file system is created.

  5. Type mount /dev/dsk/cntndnsn /mnt and press Return. The file system is mounted on a temporary mount point.


Note - You specify the block device directory (/dev/dsk) to mount the disk, not the raw device directory.

  1. Type cd /mnt and press Return.

    You have changed to the mount-point directory.

  2. Write-protect the tapes for safety.

  3. Insert the first volume of the level 0 tape in the tape drive.

  4. Type ufsrestore rvf /dev/rmt/unit and press Return. The level 0 dump is restored. If the dump required multiple tapes, you will be prompted to load the next tape.

  1. Remove the tape and load the next tape in the drive.

    Always restore tapes starting with 0 and continuing until you reach the highest level.

  1. Type ufsrestore rvf /dev/rmt/unit and press Return. The next level tape is restored. If the dump required multiple tapes, you will be prompted to load the next tape.

  2. Type rm restoresymtable and press Return. The restoresymtable created by ufsrestore is removed.

  3. Type cd / and press Return.

  4. Type umount /mnt and press Return.

    The file system is unmounted.

  5. Remove the last tape and insert a new tape that is not write-protected in the tape drive.

  6. Type ufsdump 0uf /dev/rmt/unit /dev/rdsk/cntndnsn and press Return.

    You should always do an immediate backup of a newly created file system because ufsrestore repositions the files and changes the inode allocation.

  7. Type mount /dev/dsk/cntndns and press Return. The restored file system is mounted and available for use.

    Example: How to Restore a Complete File System In this example, the file system on /dev/rdsk/c0t3d0s7 is restored:

    Code Example 8-1 Restoring /dev/rdsk/c0t3d0s7 (1 of 3)


  # newfs /dev/rdsk/c0t3d0s7  
  newfs: construct a new file system /dev/rdsk/c0t3d0s7: (y/n)? y  
  /dev/rdsk/c0t3d0s7   406296 sectors in 1254 cylinders of 9 tracks, 36 sectors  
        208.0MB in 79 cyl groups (16 c/g, 2.65MB/g, 1216 i/g)  
  super-block backups (for fsck -F ufs -o b=#) at:  
   32, 5264, 10496, 15728, 20960, 26192, 31424, 36656, 41888,  
   47120, 52352, 57584, 62816, 68048, 73280, 78512, 82976, 88208,  
   93440, 98672, 103904, 109136, 114368, 119600, 124832, 130064, 135296,  
   140528, 145760, 150992, 156224, 161456, 165920, 171152, 176384, 181616,  
   186848, 192080, 197312, 202544, 207776, 213008, 218240, 223472, 228704,  

Code Example 8-1 Restoring /dev/rdsk/c0t3d0s7 (2 of 3)

   233936, 239168, 244400, 248864, 254096, 259328, 264560, 269792, 275024,  
   280256, 285488, 290720, 295952, 301184, 306416, 311648, 316880, 322112,  
   327344, 331808, 337040, 342272, 347504, 352736, 357968, 363200, 368432,  
   373664, 378896, 384128, 389360, 394592, 399824, 405056,  
  # mount /dev/dsk/c0t3d0s7 /mnt  
  # cd /mnt  
  # ufsrestore rvf /dev/rmt/0  
  Verify volume and initialize maps  
  Media block size is 126  
  Dump   date: Wed Mar 11 10:16:53 1994  
  Dumped from: the epoch  
  Level 0 dump of /export/home on mars:/dev/dsk/c0t3d0s7  
  Label: none  
  Begin level 0 restore  
  Initialize symbol table.  
  Extract directories from tape  
  Calculate extraction list.  
  Warning: ./lost+found: File exists  
  Make node ./pubs  
  Make node ./pubs/.wastebasket  
  Make node ./pubs/Junk  
  Extract new leaves.  
  Check pointing the restore  
  extract file ./pubs/.cshrc  
  extract file ./pubs/.login  
  extract file ./pubs/.profile  
  extract file ./pubs/.Xdefaults  
  extract file ./pubs/.openwin-init.BAK  
  extract file ./pubs/junk  
  extract file ./pubs/.desksetdefaults  
  extract file ./pubs/dead.letter  
  extract file ./pubs/.openwin-init  
  extract file ./pubs/.mtdeletelog  
  extract file ./pubs/backup.examples  
  extract file ./pubs/core  
  extract file ./pubs/backup.examples%  
  extract file ./pubs/.Xauthority  
  Add links  
  Set directory mode, owner, and times.  
  Check the symbol table.  
  Check pointing the restore  
  # ls  

Code Example 8-1 Restoring /dev/rdsk/c0t3d0s7 (3 of 3)

  ./                lost+found/       restoresymtable  
  ../               pubs/  
  # rm restoresymtable  
  # cd /  
  # umount /mnt  
  # ufsdump 0ucf /dev/rmt/0 /dev/rdsk/c0t3d0s7  
    DUMP: Writing 63 Kilobyte records  
    DUMP: Date of this level 0 dump: Wed Mar 11 10:30:58 1994  
    DUMP: Date of last level 0 dump: the epoch  
    DUMP: Dumping /dev/rdsk/c0t3d0s7 (/export/home) to /dev/rmt/0  
    DUMP: mapping (Pass I) [regular files]  
    DUMP: mapping (Pass II) [directories]  
    DUMP: estimated 956 blocks (478KB)  
    DUMP: dumping (Pass III) [directories]  
    DUMP: dumping (Pass IV) [regular files]  
    DUMP: Tape rewinding  
    DUMP: 956 blocks (478KB) on 1 volume  
    DUMP: DUMP IS DONE  
    DUMP: level 0 dump on Wed Mar 11 10:30:58 1994  
  # mount /dev/dsk/c0t3d0s7  
  # mount  
  / on /dev/dsk/c0t0d0s0 read/write on Wed Mar 11 09:38:31 1994  
  /usr on /dev/dsk/c0t0d0s6 read/write on Wed Mar 11 09:38:31 1994  
  /proc on /proc read/write on Wed Mar 11 09:38:31 1994  
  /dev/fd on fd read/write on Wed Mar 11 09:38:31 1994  
  /tmp on swap  on Wed Mar 11 09:38:33 1994  
  /opt on /dev/dsk/c0t0d0s7 setuid on Wed Mar 11 09:38:36 1994  
  /export/home on /dev/dsk/c0t3d0s7 setuid on Wed Mar 11 10:32:02 1994  
  #  

Restoring / and /usr File Systems

See the Administration Supplement for Solaris Platforms for instructions on how to restore the / and /usr file systems.

Restoring Individual Files and Directories

This section describes how to restore individual files and directories using a local tape drive. See "Using a Remote Drive to Restore Files" on page 150 for information on how to use a remote drive to restore 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 files to /home1 that were backed up from /home/doc/books the files are restored in the directory /home1/doc/books.
When restoring individual files and directories, it is a good idea to restore them to a temporary directory such as /var/tmp. After you verify them, you can move the files to their proper locations. You can restore individual files and directories to their original locations. If you do so, be sure you are not overwriting newer files with older versions from the backup tape.
· How to Restore Files Interactively
  1. Become superuser.

  2. Write-protect the tape for safety.

  3. Put the backup tape in the tape drive.

  4. Type cd /var/tmp and press Return.

    If you want to restore the files to a different directory, substitute the directory name for /var/tmp in this step.

  5. Type ufsrestore if /dev/rmt/unit and press Return. Some informational messages and the restore > prompt are displayed.

  6. Create a list of files to be restored.

    a. To list the contents of a directory, type ls and press Return. b. To change directories, type cd directory-name and press Return.

    c. To add a directory or file name to the list of files to be restored, type

    add filename and press Return.

    d. To remove a directory or file name from the list of files to be restored, type delete filename and press Return.

    e. To keep the mode of the current directory unchanged, type setmodes and press Return. Then type n and press Return.

    See "Options and Arguments for the ufsrestore Command" on page 151 for more information about the setmodes command.

  7. When the list is complete, type extract and press Return. ufsrestore asks you which volume number to use.

  1. Type the volume number and press Return. If you have only one volume, type 1 and press Return.

    The files and directories in the list are extracted and restored to the current working directory.

  2. Type quit and press Return.

    The shell prompt is displayed.

  1. Use the ls -l command to list the restored files and directories. A list of files and directories is displayed.

  1. Check the list to be sure all the files and directories you specified in the list have been restored.

  2. Use the mv command to move the files to the proper directories.

    Example: How to Restore Files Interactively In this example, the files backup.examples and junk are restored from the pubs directory:


  # cd /var/tmp  
  # ufsrestore if /dev/rmt/0  
  ufsrestore > ls  
  .:  
   lost+found/   pubs/  
  
  ufsrestore > cd pubs  
  ufsrestore > ls  
  ./pubs:  
  .Xauthority      .login             .profile  
  backup.examples%  
  .Xdefaults      .mtdeletelog       .wastebasket/       core  
  .cshrc          .openwin-init      Junk/               dead.letter  
  .desksetdefaults .openwin-init.BAK  backup.examples     junk  
  
  ufsrestore > add backup.examples  
  ufsrestore > add junk  
  ufsrestore > setmodes  
  set owner/mode for '.'? [yn] n  
  ufsrestore > extract  
  You have not read any volumes yet.  
  Unless you know which volume your file(s) are on you should start  


  with the last volume and work towards the first.  
  Specify next volume #: 1  
  set owner/mode for '.'? [yn] n  
  ufsrestore > quit  
  # ls -l  
  total 6  
  drwxrwxrwt   3 sys      sys          512 Mar 11 10:36 ./  
  drwxrwxr-x  18 root     sys          512 Mar 10 16:43 ../  
  drwxr-xr-x   2 pubs     staff        512 Mar 11 10:11 pubs/  
  # pwd  
  /var/tmp  
  # cd pubs  
  # ls  
  ./                ../               backup.examples   junk  
  #  

· How to Restore Specific Files
  1. Become superuser.

  2. Write-protect the tape for safety.

  3. Put the backup tape in the tape drive.

  4. Type cd /var/tmp and press Return.

    If you want to restore the files to a different directory, substitute the directory name for /var/tmp in this step.

  5. Type ufsrestore xf /dev/rmt/unit filename and press Return. The x option tells ufsrestore to copy specific files or directories in the filename argument.

  6. Type the volume number where files are located and press Return.

    The file is restored to the current working directory. The message set owner/mode for '.'? [yn] is displayed.

  7. Type n and press Return.

    Directory modes remain unchanged.

  8. Type ls -l filename and press Return.

    A listing for the file is displayed.

  9. Use the mv command to move the file to the proper directory.

Example: How to Restore a Specific File In this example, the /pubs/backup.examples file is restored to the /var/tmp directory:

  # cd /var/tmp  
  # ufsrestore xf /dev/rmt/0 pubs/backup.examples  
  You have not read any volumes yet.  
  Unless you know which volume your file(s) are on you should start  
  with the last volume and work towards the first.  
  Specify next volume #: 1  
  set owner/mode for '.'? [yn] n  
  # ls  
  ./     ../    pubs/  
  # cd pubs  
  # ls  
  ./                ../               backup.examples  
  #  

Using a Remote Drive to Restore Files

You can restore files from a remote drive by adding remote-host: to the front of the tape device name. Here is the syntax:
ufsrestore rf [user@]remote-host:/dev/rmt/unit filename

For example, to access a remote tape drive /dev/rmt/0 on the system venus, type:

  # ufsrestore rf venus:/dev/rmt/0 filename  

Troubleshooting

Make Sure the Backup and Restore Commands Match

You can only use ufsrestore to restore files backed up with ufsdump. If you backup with tar, restore with tar. If you use the ufsrestore command to restore a tape that was written with another command, an error message tells you that the tape is not in ufsdump format.

Check to Make Sure You Have the Right Current Directory

It is easy to restore files to the wrong location. Because the ufsdump command always copies files with full path names relative to the root of the file system, you should usually change to the root directory of the file system before running ufsrestore. If you change to a lower-level directory, after you restore the files you will see a complete file tree created under that directory.

Use the Old restore Command to Restore Multivolume Diskette Backups

You cannot use the ufsrestore command to restore files from a multivolume backup set of diskettes made with the dump command. You must restore the files on a SunOS 4.x system.

Options and Arguments for the ufsrestore Command

Command Syntax

The syntax of ufsrestore is:
ufsrestore [options][arguments][filename(s) ...]
options is a single string of one-letter option names. arguments follows the option string with the arguments that match the options. The option names and the arguments that go with them must be in the same order. The filename(s) argument, which goes with either the x or t options, must always come last.

Note - You must choose one and only one of these options: i, r, R, t, or x.

Options and Arguments

You must use one (and only one) of the ufsrestore options shown in Table 8-1.
Table 8-1 ufsrestore
OptionDescription
iInteractive. Runs ufsrestore in an interactive mode. In this mode, you can use a limited set of shell commands to browse the contents of the media and select individual files or directories to restore. See "Interactive Commands" on page 154 for a list of available commands.
rRecursive. 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 (e.g., restoresymtable) is also included. To completely restore a file system, use this option to restore the full (level 0) dump and then for each incremental dump. Although intended for a new file system (one just created with the newfs command), the file system may contain files and files not on the backup media are preserved.
RResume 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.
x [filename(s)...]Extract. Selectively restores the files you specify by 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 also. If you omit filename(s) 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(s)...]Table of contents. Checks the files specified in the filename(s) 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(s) 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(s), 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.
In addition to one of the options shown in Table 8-1, you can choose from the options shown in Table 8-2.
Table 8-2 ufsrestore
OptionDescription
a archive-file [filename(s)...]Takes the dump table of contents from the specified archive-file 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 will be prompted to mount the appropriate volume before extracting the file(s).
b factorBlocking factor. Number of 512-byte blocks to write to tape per operation. By default, ufsrestore tries to figure out the block size used in writing the tape.
dDebug. Turn on debugging messages.
f backup-fileBackup 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.
hTurns off directory expansion. Only the directory file you specify is extracted or listed.
mRestores 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 nSkips to the nth backup file on the media. This option is useful when you put more than one backup on a single tape.
vVerbose. Displays the names and inode numbers of each file as it is restored.
yContinues when errors occur reading the media and tries to skip over bad blocks instead of stopping
and asking whether to abort. This option tells the command to assume a yes response.

Interactive Commands

When you use the interactive command, a restore > prompt is displayed, as shown in this example:

  jupiter% ufsrestore ivf /dev/rmt/0  
  Verify volume and initialize maps  
  Tape block size is 126  
  Dump date: Tue Aug 18 09:06:43 1989  
  Dumped from: Fri Aug 14 08:25:10 1989  
  Level 0 dump of /usr on pilgrim:/dev/dsk/c0t1d0s6  
  Label:none  
  Extract directories from tape  
  Initialize symbol table.  
  restore >  

At the restore > prompt, you can use the commands shown in Table 8-3 to find files, create a list of files to be restored, and restore them.
Table 8-3
OptionDescription
ls [directory-name]Lists the contents of either the current directory or the specified 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-nameChanges 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 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 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 media.
Table 8-3 (Continued)
OptionDescription
extractExtracts the files in the list and restores them to the current working directory on the disk. Specify 1 when asked for a volume number. If you are doing a multitape or multidiskette restore and restoring a small number of files, start with the last tape or diskette.
helpDisplays a list of commands you can use in interactive mode.
pwdDisplays the path name of the current working directory in the backup hierarchy.
qQuits interactive mode without restoring any additional files.
setmodesLets 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.
verboseTurns 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 display information on each file as it is extracted.
whatDisplays the backup header on the tape or diskette.