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 ArchivesIndividual 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]
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.
11.4.2 Restoring from dump ArchivesThe 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:
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 modeThe 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
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 utilityThe 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:
11.4.3 Moving Data Between SystemsIn 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:
|