20.4 Restoring Files from Tape with tarWhen you create an archive, there are several ways to specify the directory. If the directory is under the current directory, you could type: % A similar way to specify the same directory is: % If you are currently in the directory you want archived, you can type: % Another way to archive the current directory is to type: % Here, the shell expands the
This causes a problem when restoring a directory from a
tar
archive.
You may not know if an archive was created using I always check the names of the files before restoring an archive: % If the archive loads the files into the current directory, I create a new directory, change to it, and extract the files. If the archive restores the directory by name, then I restore the files into the current directory. 20.4.1 Restoring a Few FilesIf you want to restore a single file, get the pathname
of the file as
tar
knows it, using the
t
flag.
You must specify the exact filename, because
% Whenever you use tar to restore a directory, you must always specify some filename. If none is specified, no files are restored. There is still the problem of restoring a directory whose pathname starts with / (slash). Because tar restores a file to the pathname specified in the archive, you cannot change where the file will be restored. The danger is that either you may overwrite some existing files or you will not be able to restore the files because you don't have permission. You can ask the system administrator to rename a directory and temporarily create a symbolic link pointing to a directory where you can restore the files. Other solutions exist, including editing the tar archive and creating a new directory structure with a C program executing the chroot (2) system call. Another solution is to use the version from the Free Software Foundation (52.9 ) that allows you to remap pathnames starting with / (slash). It also allows you to create archives that are too large for a single tape, incremental archives, and a dozen other advantages. This freely available version of tar is also called GNU tar (19.6 ) . (It's on the disc.) But the best solution is to never create an archive
of a directory that starts with
20.4.2 Remote RestoringTo restore a directory from a remote host, use the following command:
Because of its nature, it is difficult to read fixed-size blocks over a network. This is why tar uses the B flag to force it to read from the pipe until a block is completely filled. [Some versions of tar , like the one from GNU (52.9 ) on the CD-ROM, handle remote drives automatically. -JIK ] - |
|