33.4. Restore files with tar

More important than performing regular backups is having them available when we need to recover important files! In this section, we will discuss methods for restoring files, which have been backed up with tar command.

The following command will restore all files from the full-backup-Day-Month-Year.tar archive, which is an example backup of our home directory created from the example tar commands shown above.


[root@deep] /# cd /
[root@deep] /# tar xpf /dev/st0/full-backup-Day-Month-Year.tar
The above command extracts all files contained in the compressed archive, preserving original file ownership and permissions.

If you do not need to restore all the files contained in the archive, you can specify one or more files that you wish to restore: To specify one or more files that you wish to restore, use the following command:


[root@deep]# cd /
[root@deep]# tar xpf /dev/st0/full-backup-Day-Month-Year.tar \
 home/wahib/Personal/Contents.doc home/quota.user
 
The above command restores the /home/wahib/Personal/Contents.doc and /home/quota.user files from the archive.

If you just want to see what files are in the backup volume, Use the --list or -t option:


[root@deep] /# tar tf /dev/st0

Caution

If you have files on your system set with the immutable bit, using the chattr command, these files will not be remembered with the immutable bit from your restored backup. You must reset it immutable with the command chattr +i after the backup is completed.

Note

Test the ability to recover: Dont forget to test the ability to recover from backups, for many system administrators, recovering a file from a backup is an uncommon activity. This step assures that if you need to recover a file, the tools and processes will work. Performing this test periodically will help you to discover problems with the backup procedures so you can correct them before losing data. Some backup restoration software does not accurately recover the correct file protection and file ownership controls. Check the attributes of restored files to ensure they are being set correctly. Periodically test to ensure that you can perform a full system recovery from your backups.

Further documentation, for more details, there is man page you can read:

tar(1)

- The GNU version of the tar archiving utility