Restoring files with tar
Keywords: sag

Next: Multilevel backups Up: Simple backups Previous: Making backups with tar

## Restoring files with `tar`

The `-extract` (`-x`) option for `tar` extracts files:

> `# tar -extract -same-permissions -verbose -file /dev/fd0H1440
> usr/src/
> usr/src/linux
> usr/src/linux-1.2.10-includes/
> usr/src/linux-1.2.10-includes/include/
> usr/src/linux-1.2.10-includes/include/linux/
> usr/src/linux-1.2.10-includes/include/linux/hdreg.h
> usr/src/linux-1.2.10-includes/include/linux/kernel.h
> ...
> #`

You also extract only specific files or directories (which includes all their files and subdirectories) by naming on the command line:

> `# tar xpvf /dev/fd0H1440 usr/src/linux-1.2.10-includes/include/linux/hdreg.h
> usr/src/linux-1.2.10-includes/include/linux/hdreg.h
> #`

Use the `-list` (`-t`) option, if you just want to see what files are on a backup volume:

> `# tar -list -file /dev/fd0H1440
> usr/src/
> usr/src/linux
> usr/src/linux-1.2.10-includes/
> usr/src/linux-1.2.10-includes/include/
> usr/src/linux-1.2.10-includes/include/linux/
> usr/src/linux-1.2.10-includes/include/linux/hdreg.h
> usr/src/linux-1.2.10-includes/include/linux/kernel.h
> ...
> #`

Note that `tar` always reads the backup volume sequentially, so for large volumes it is rather slow. It is not possible, however, to use random access database techniques when using a tape drive or some other sequential medium.

`tar` doesn't handle deleted files properly. If you need to restore a filesystem from a full and an incremental backup, and you have deleted a file between the two backups, it will exist again after you have done the restore. This can be a big problem, if the file has sensitive data that should no longer be available.