11.4 Restoring Files from Backups


All of the backup facilities described in the previous sections have corresponding file restoration facilities. We'll look at each of them in turn in this section.

11.4.1 Restores from tar and cpio Archives

Individual files or entire subtrees can be restored easily from tar and cpio archives. For example, the following pairs of commands restore the file /home/chavez/freeway/quake95.data and user harvey's home directory (respectively) from an archive made of /home located on the tape in the default tape drive (here, we use /dev/rmt0 for as the example location):

$ tar -xp /home/chavez/freeway/quake95.data $ cpio -im '*quake95.data' < /dev/rmt0 $ tar -xp /home/harvey $ cpio -imd '/home/harvey*' < /dev/rmt0

The -p option to tar and -m option to cpio ensure that all file attributes are restored along with the file. cpio's -d option creates subdirectories as necessary when restoring a directory subtree (tar does so by default).[17]

[17] The second cpio command also assumes that there is no file or directory in /home that begins with "harvey" other than user harvey's home directory.

Restores with pax are similar. For example, the first of the following commands lists the files on the tape in drive 0, and the remaining commands extract various files from it:

$ pax -f /dev/rmt0 -v               -v gives a more detailed/verbose listing.  $ pax -r '/h95/*.exe'               Select files via a regular expression.  $ pax -r /home/chavez               Restore chavez's home directory.  $ pax -r -f my_archive -c '*.o'     Restore everything except object files. # pax -r -pe -f /dev/rmt0           Restore files incl. owner, mode & mod. time. 

pax's coolest feature has to be its -s option, which allows you to massage filenames as files are written to, extracted from, or even just listed from an archive. It takes a substitution command as used in ed or sed as its argument (which will usually need to be enclosed in single quotation marks) indicating how filenames should be transformed. For example, the following command changes the second-level directory name of each file from chavez to harvey as files are read from the archive, changing their target location on disk:

$ pax -r -s ',^/home/chavez/,/home/harvey/,' \       -f /dev/rmt0 /home/chavez

The substitution clause searches for /home/chavez at the beginning of the pathname of each file to be restored and changes it to /home/harvey, using commas as the field separator within the substitution string.

Here are some additional -s clauses for specific kinds of transformations:

-s ',^/home/chavez/,,'     Remove partial directory component.  -s ',^.*//*,,'             Remove entire directory component.   -s ',^//*,,'               Make pathnames relative to current directory. 

Multiple -s options are allowed, but only the first matching one is used for any given filename.

Be aware that pax is not without its eccentricities. One of the most annoying is the following: in some versions of pax, directories matched via wildcards in the pattern list during restore operations are not extracted in their entirety; only explicitly listed ones are. Note that this is the opposite of the way cpio works and also counter to the way tar operates. I'd be positive this was a bug except that it happens in more than one vendor's version, although not in every vendor's version. With pax, caveat emptor would appear to be the watchword.

11.4.2 Restoring from dump Archives

The restore utility retrieves files from backup tapes made with the dump utility. It is supported by those systems supporting a version of dump. Solaris calls its version ufsrestore in keeping with the name of its version of dump. HP-UX and Tru64 provide vxrestore and vrestore commands for their default filesystem types. All of these commands have the same syntax and options. The commands can restore single files, directories, or entire filesystems.

To restore an entire filesystem, you must restore the most recent backup tapes from each backup level: the most recent full dump (0), the most recent level 1 dump, and so on. You must restore each level in numerical order, beginning with level 0. restore places the files it retrieves in the current working directory. Therefore, to restore a filesystem as a whole, you may wish to create and mount a clean, empty filesystem, make the current working directory the directory in which this filesystem is mounted, and then use restore to read the backup tapes into this directory. Note that such restore operations will have the side effect of recreating deleted files.

After a full restore, you need to do a full (level 0) backup. The reason for this is that dump backs up files by their inode number internally, so the tape from which you just restored from won't match the inodes in the new filesystem since they were assigned sequentially as files were restored.

In general, the restore command has the following forms (similar to dump's):

$ restore options-with-arguments  [files-and-directories ] $ restore option-letters  corresponding-arguments  [files-and-directories ]

where files-and-directories is a list of files and directories for restore to retrieve from the backup tape. If no files are listed, the entire tape will be restored.

In the first, newer form, the first item is the list of options to be used for this backup with their arguments immediately following the option letters in the normal way (e.g., -f /dev/tape). In the second, older form, option-letters is a list of argument letters for the desired options, and corresponding-arguments are the values associated with each argument, in the same order. This syntax is still the only one available under AIX and Solaris.

Most options to restore do not have any arguments. However, as with dump, it is important that any arguments appear in the same order as the options requiring them.

restore places the files that it retrieves in the current working directory. When a directory is selected for restoration, restore restores the directory and all the files within it, unless you have specified the -h option (described later in this section).

restore's most important options are the following:

-r

Read and restore the entire tape. This is a very powerful command; it should be used only to restore an entire filesystem located on one or more tapes. The filesystem into which the tape is read should be newly created and completely empty. This option can also be used to restore a complete incremental dump on top of a newly restored filesystem. That is, after using the -r option to restore the most recent full dump, you use it again to restore successive incremental dumps until the filesystem has been completely restored.

-x

Extract all files and directories listed and restore them in the current directory. Each filename to be extracted must be a complete pathname relative to the root directory of the filesystem being restored. For example, to restore the file /chem/pub/old/gold.dat from a dump of the /chem filesystem, you must specify the filename as pub/old/gold.dat. You should be in /chem when you execute the restore command if you want the file to be restored to its original location.

-t

Type the names of the listed files and directories if they appear on the backup tape. This option lets you find out whether a given file is on a particular tape more quickly than reading the entire tape. When used without a file list, it verifies that a dump tape is readable.

-f file

The corresponding argument is the name of the file or device holding the dump. If this option is omitted, restore assumes that the dump tape is mounted on your default tape drive. Use a hyphen for file to specify standard input.

-s n

The value n indicates which file on tape is to be used for the restore. For example, -s 3 says to use the third tape file.

-i

Enter interactive mode. This is almost always the most convenient method for restoring a small group of files. It is described in detail in the next section.

A typical usage of the restore command is:

# cd /home # restore -x -f /dev/rmt1 chavez/mystuff others/myprogram

This restores the directory /home/chavez/mystuff and the file called /home/others/myprogram from a backup tape (assuming that /home is the filesystem in the archive). The directories chavez and others are assumed to be in the current directory (and created if necessary), and the specified subdirectory and file are restored under them. These both originally resided within the /home directory. Note, however, that the mount point name is not used in the restore command. The command must be executed from /home to restore the files to their original locations.

On Solaris and HP-UX systems, the corresponding options would be:

xf /dev/rmt1 chavez/mystuff others/myprogram

dump and restore both save files independently of where the filesystem happens to be mounted at the time; that is, the pathnames used by these commands are relative to their position in their own filesystem, not in the overall system filesystem. This makes sense, because the filesystem could potentially be mounted anywhere in the overall directory tree, and files should still be able to be restored to their correct location relative to the current mount point for their filesystem.

If you need to restore some files that have been destroyed by accident, your most difficult problems will be determining which set of backup tapes contains these files and waiting for the system to read through one or more full backup tapes. If you do incremental backups, knowing when a file was last modified will help you to find the correct backup tape. Creating online table-of-contents files is also very useful (this topic is discussed later in this chapter).

11.4.2.1 The restore utility's interactive mode

The interactive mode is entered with restore's -i option. Once there, the contents of a tape can be scanned and files chosen for extraction. This mode's use is illustrated in this sample session:

$ restore -i -f /dev/rmt1          Initiate restore's interactive mode.  restore > help  Available commands are:        ls [arg] - list directory        cd arg - change directory        add [arg] - add `arg' to list of files to be extracted        delete [arg] - delete `arg' from list of files to be extracted     extract - extract requested files     ...  If no `arg' is supplied, the current directory is used  restore > ls                       List directory on tape.  chavez/    harvey/     /ng   restore > cd chavez/vp             Change tape current directory. restore > ls   v_a.c      v_a1.c      v_b3.c      v_d23.c      v_early   restore > add v_a1.c               Select (mark) files to be restored. restore > add v_early  restore > ls   v_a.c     *v_a1.c      v_b3.c      v_d23.c     *v_early  restore > delete v_early           Remove a file from the extract list..  restore > extract                  Write selected files to current directory.  You have not read any tapes 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           Tape number if known. set owner/mode for '.'? [yn] n     Don't change ./'s ownership or protection. restore > quit                     End the restore interactive session. 

The final prompt from restore asks whether to change the ownership and protection of the current directory to match that of the root directory on the tape. Answer yes only if you are restoring an entire filesystem.

NOTE

figs/armadillo_tip.gif

If you want to place several archives onto the same tape, all you need to do is rewind the tape (if necessary) before writing the first archive and then use a nonrewinding device for all subsequent backup operations.

To retrieve files from a multiarchive tape, you must position the tape at the proper location before issuing the restoration command. restore can do this automatically using its -s option, which takes the tape file number you want to use as its argument.

For all other backup types, position the tape with the mt command. For example, the following commands position the tape just after the second archive on the tape:

$ mt -f /dev/rmt0 rewind     If necessary  $ mt -f /dev/nrmt0 fsf 2

Again, you will need to use the nonrewinding form of the tape device; otherwise, the tape will be rewound to the beginning after positioning. Once at the desired point, you can write an additional backup archive to the tape or perform a restore operation using the next archive on the tape, as appropriate.

11.4.2.2 The HP-UX frecover utility

The HP-UX frecover utility restores files archived by fbackup, using a very similar syntax. For example, the first of the following commands restores the /chem/fullerenes subdirectory tree:

# frecover -x -i /chem/fullerenes # frecover -r -f /dev/rmt/1m

The second command restores all files on the tape in drive 1. frecover also accepts the -i, -e, and -g options. Other useful options include the following:

  • -X and -F restore all retrieved files relative to the current directory (converting absolute pathnames to relative ones) or into the current directory (stripping off all paths), respectively.

  • -o says to overwrite files on disk that are newer than the file in the backup set.

  • -N says to read the backup media without restoring any files. It is useful for verifying the integrity of a backup and for creating table-of-contents files.

11.4.3 Moving Data Between Systems

In general, tar, cpio, and dump write archives that are readable on many different computer systems. However, sometimes you will run into problems reading a tape on a system other than the one on which it was written. There are four major causes for such problems:

Block size differences

The simplest cause of tape reading problems is a difference in the block size with which the archive was written and the block size expected by the drive on which you're trying to read it. Some tape drives assume specific fixed block sizes. You can specify the block size to backup and restore utilities (-b is often the relevant option), and on many systems you can set the characteristics of the drive itself. The most commonly used block sizes are 512 and 1024.

Archive format incompatibilities

The backup utilities provided by early versions of Unix differed from those in use today, so very old computer systems may not be able to read tapes written on a current machine. The modern versions of most utilities include backward-compatibility options that allow you to write tapes in the old format if you need to read them on an ancient system.

Byte order differences

Whether a computer system is big endian or little endian determines how it interprets the individual bytes within larger data units, such as words. Big-endian systems consider the byte with the lowest address as the most significant; little-endian systems consider it to be the least significant. Tape archives, like all other data on a computer system, reflect this fundamental attribute of the hardware. When you want to read a tape produced by a computer of one type on a different computer of the other type, you'll need to swap the bytes before utilities like tar can make sense of the archive.

For example, you could use this AIX command to list the contents of a tape written on an IRIX system:

$ dd if=/dev/rmt1 conv=swab | tar tvf - 

The dd command reads the tape file and swaps the bytes, passing the converted archive to the tar command, which lists the archive it finds on standard input. You could construct the equivalent reversed pipe to produce a byte-swapped archive on tape.

Compressed archives

If you write a tape on a drive that performs automatic data compression, you won't be able to read it on a drive that lacks this feature. In order to write tapes that will be readable on drives without compression, you'll need to specify the noncompressing special file to the backup utility (refer to the discussion of special files earlier in this chapter, as well as the relevant manual pages for your systems, for details).



Essential System Administration
Essential System Administration, Third Edition
ISBN: 0596003439
EAN: 2147483647
Year: 2002
Pages: 162

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net