Tar and Taper for Linux

In plain English, Yusuf Nagree explains archival backup with tar and his user-friendly taper program.

This article describes backing up files on a Linux system. Two programs are described—tar and taper. The first program is available from the Free Software Foundation under the GNU license and is included with most distributions of Linux. The second program is written by the author of this article and provides a more user friendly interface. It is also available under the GNU license and thus is freely available. Note that this article is not meant to be a full reference for either package, but merely an introduction to get you started. For full details, see the documentation that comes with each package.

tar

Nearly every form and clone of Unix (as well as other operating systems) comes with some version of tar. It is a standard program, and archives made on one machine should always be usable on other machines. The real problem with tar is that there is virtually no user-interface at all. All operations must be done via command line switches.

Making a Backup

tar can make backups to a hard disk file or to a tape drive as well as over a NFS link (which we won't cover here). The files to be backed up can be compressed using GNU gzip (or compress).

To make a backup, the basic form is:

$ tar [options] files_to_backup_or_restore

The most commonly used options are:

c

Creates a new archive.

z

Compresses the archive using GNU gzip.

Z

Compresses the archive using compress.

f name

Use name as the archive file or device. The default is documented as /dev/rmt0, although some people have changed this so that the default is /dev/nst0, /dev/tape, or even standard input. It is usually safer to explicitly give the device name of your tape drive all the time.

r

Append files to existing archive. Note that if you use ftape, this option will not work because of a limitation in the current ftape driver.

u

Append files to existing archive but only if they are newer than the files already in the archive. Once again, if you use ftape, this option will not work.

Thus, to create a compressed backup of your /etc directory in a file called etc_backup.tar, you would do:

$ tar czf etc_backup.tar /etc

Note that all subdirectories under /etc will be backed up as well.

If you now want to add the contents of /usr/local/etc, you would do: $ tar rzf etc_backup.tar /usr/local/etc

Suppose that you have now made some changes to the files, but not all of them. You can do:

$ tar uzf etc_backup.tar /etc /usr/local/etc

and tar will go through and append to the archive only those files that have been changed since the archive was originally created.

The above examples apply to backing up to a file on the hard disk. Backing up to a tape drive simply involves giving the filename of the tape device, usually /dev/ftape for floppy tape drives and /dev/st0 for SCSI tape drives.

Restoring

The two options that are relevant here are:

x

Means extract file from archive. If no filenames are specified, all the files in the archive are extracted.

t

Means print table of contents; prints names of files that would be extracted but does not actually extract the files.

Thus, to restore the contents of the backup in the above example, you would do:

$ tar xzf etc_backup.tar

Note that tar does not put the files back where they came from, but rather creates a new tree based on the current directory. For example, if you were in the /usr/home/john directory when you issued the above command, you will find that a new subdirectory /usr/home/john/etc has been created and all the files are in that subdirectory. If you wish to restore the files whence they came:

$ cd /$ tar xzf etc_backup.tar

Note that doing this is very dangerous, since old files are over-written without warning. This can have dire consequences if not used properly. It is often much safer to restore in your home directory or /tmp and then copy the files to their correct location after you have checked that nothing horrible will happen.

To restore an individual file or directory, simply specify the name after all the tar arguments. For example, to restore just the hosts and the passwd file:

$ tar xzf etc_backup.tar etc/hosts etc/passwd

Note that the full pathname (excluding the leading /, which tar explicitly does not store) needs to be specified.

______________________

Webcast
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers

Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.

Learn More

Sponsored by AMD

White Paper
Red Hat White Paper: Using an Open Source Framework to Catch the Bad Guy

Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6

Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.

Learn more about catching the bad guy in this free white paper.

Learn More

Sponsored by DLT Solutions