Restoring Backed Up Files

The restore command is used to retrieve files from a backup tape or other medium that was created by dump. You can use restore to recover an entire file system or to interactively select individual files. It recovers files from the specified media and copies them into the current directory (the one you ran the recover command in), re-creating subdirectories as needed. Much as with the dump command, the first parameter passed to the restore command is a list of single character option codes, as shown in Table 13-5.

Table 13-5: Restore Command Options

Restore Options



Restore the entire dump archive.


Compare the contents of the dump file with the files on the disk. This is used to check the success of a restore.


Start the restore from a particular tape of a multitape backup. This is useful for restarting an interrupted restore

-X filelist

Extract only specific files or directories from the archive. This option takes one argument, a list of files or directories to extract

-T file

List the contents of the dump archive. If a file or directory is given as an argument, list only the occurrence of that file, directory, or anything within the directory.


Restore files in interactive mode.

-b blocksize

Specify the block size of the dump in kilobytes. This option takes a numeric argument.


Specify the name of the file system to be compared when using the


-C option. The file system name is passed as an argument.

-F script

Specify the name of the dump archive to restore from. This option takes an alphanumeric argument.


If this option is specified, restore re-creates directories marked for extraction but will not extract their contents.


Files are extracted by inode number instead of name. This is generally not very useful.


Instead of extracting files, print their names.

-s file#

Specify the dump file to start with on a multiple file tape. This takes a numeric argument.

-T directory

Tells restore where to write any temporary files. This is useful if you booted from a floppy disk (which has no space for temporary files).


Run in verbose mode. This causes restore to print information about each file as it restores it.


The restore command will always continue when it encounters a bad block, rather than asking you if you want to continue.

Restoring an entire file system

Let’s return to our earlier example of the Friday disk crash. You installed a shiny new hard drive and your backup tapes are in hand. It is time to restore the files. For the purpose of this example, I assume that the crashed drive contained only the /home partition and that the Fedora Linux operating system is still intact. If the crashed drive had contained the Fedora Linux operating system, you would first have to reinstall Fedora Linux before restoring the backup.

Before any files can be recovered to your new hard drive, an empty file system must be created on it. You use the mkfs command to do this. The mkfs command can accept a variety of parameters, but usually you only need to supply the name of the device to create the file system on. Thus, to prepare the new hard drive, type:

 # mkfs -t ext3 /dev/hda6 

Alternatively, because your /home drive is listed in the /etc/fstab file, you can simply specify the /home mountpoint and mkfs will figure out the correct device. Thus, the preceding command could be replaced with this:

 # mkfs /home  

You should, of course, exercise extreme caution when using the mkfs command. If you specify the wrong device name, you could unintentionally wipe out all data on an existing file system.

After creating a file system on your new disk, mount the partition to a temporary mount point.

 # mkdir /mnt/test # mount /dev/hda6 /mnt/test  

This connects the new file system to the /mnt/test directory. Now change into the directory (cd /mnt/test) and use the restore command to recover the entire file system off of your backup tape. Of course, it is assumed that you have loaded the tape into the tape drive.

 # cd /mnt/test  # restore rf /dev/nrft0  

When the restore is finished, you can unmount the partition and remount it to the appropriate mount point. If you have restored the file system to a different physical partition than it was originally on, be sure to modify the /etc/fstab file appropriately so that the correct partition is mounted next time the system is rebooted.

Recovering individual files

The restore command can also be used to recover individual files and directories. By using restore in interactive mode, you can type a series of restore commands to selectively restore files. To run restore in interactive mode, use the i parameter instead of r:

 # restore if /dev/nrst0  

The restore command will then read the file index from the backup tape and present you with a restore prompt. At this prompt, you can type the commands that enable you to select which directories and files to recover. You can navigate the directory structure of the backup index much the same way that you navigate an actual file system using a shell prompt. The interactive restore command even has its own version of the familiar cd and ls commands, as shown in Table 13-6.

Table 13-6: Interactive restore Commands




Add a file or directory to the list of files to be extracted. If a directory is marked for extraction, all of the directories and files within it will also be extracted.


Change the current directory being viewed within the dump archive. Works similar to the cd command used at a shell prompt.


Delete a file or directory from the list of files to be extracted. Deleting a directory from the list results in all of the files and directories within it also being deleted.


Extract all of the marked files and directories from the archive and write them back to the file system.


List the available commands.


List the contents of the current directory. If a directory name is provided as an argument, list the contents of that directory. Files or directories marked for extraction have a * character in front of them.


Print the full path name of the current directory of the dump archive.


Exit the interactive restore program.


Do not restore the files; instead, set the modes of already existing files on the target disk to match the modes recorded in the dump file. This is useful for recovering from a restore that was prematurely aborted.


Toggles verbose output versus quiet output during the restore process. Verbose output mode will echo information to the screen for every file that is restored.

As an example, pretend that the user joe has accidentally deleted his Mail subdirectory from his home directory. Joe happens to be your boss, so it is urgent that you recover his files. Here is how you may go about it.

Load the appropriate tape into the tape drive and log in as root. Use the cd command to go to the top of the /home partition, and then run the restore program in interactive mode:

 # cd /home # restore if /dev/nrft0  

Verify that you have the backup tape for the /home partition by entering the ls command. You should see something like the following list of directories, representing users who have home directories in /home:

restore > ls  .:  bob/        jane/       joe/        lost+found/ mary/       thad/ 

Yes, this is the home partition. Now change the current directory to Joe’s home directory using the cd command. Type ls again to view the contents of his home directory.

restore > cd joe  restore > ls  ./joe:  .mozilla/           Desktop/            report.html  .tcshrc             Mail/               letter.txt  .xinitrc            News/               www/ 

Now mark the Mail directory for extraction using the add command:

restore > add Mail 

If you use the ls command again, you see that the Mail directory is preceded with an asterisk (*) character, which means it has been marked for extraction.

restore > ls  ./joe:  .mozilla/            Desktop/             report.html  .tcshrc             *Mail/                letter.txt  .xinitrc             News/                www/  

Now use the extract command to begin the extraction process. restore will prompt you for the number of the tape to start with. This is a single tape backup, so just enter the number 1. When it prompts you to "set owner/mode for '.'?," answer yes by typing y and pressing Enter. restore will then restore the file permissions (if necessary) of the directory it is restoring to. This isn’t critical when extracting individual files like this, but you should always answer yes to this prompt when doing a full restore. Anyway, your screen should now contain the following:

restore > extract 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 toward the first.  Specify next volume #: 1 set owner/mode for '.'? [yn] y restore > 

At this point, the files have been recovered and you can exit the restore program by issuing the quit command. That's all there is to it. You now know the basics of using the dump and restore commands.

Red Hat Fedora Linux 3 Bible
Red Hat Fedora Linux 3 Bible
ISBN: 0764578723
EAN: 2147483647
Year: 2005
Pages: 286 © 2008-2017.
If you may any questions please contact us: