Tar and Taper for Linux
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.
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.
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:
Creates a new archive.
Compresses the archive using GNU gzip.
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.
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.
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.
The two options that are relevant here are:
Means extract file from archive. If no filenames are specified, all the files in the archive are extracted.
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.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Server Hardening
- BitTorrent Inc.'s Sync
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- New Container Image Standard Promises More Portable Apps
- The Humble Hacker?
- The Death of RoboVM
- The US Government and Open-Source Software
- Open-Source Project Secretly Funded by CIA
- EnterpriseDB's EDB Postgres Advanced Server and EDB Postgres Enterprise Manager
- Varnish Software's Hitch
In modern computer systems, privacy and security are mandatory. However, connections from the outside over public networks automatically imply risks. One easily available solution to avoid eavesdroppers’ attempts is SSH. But, its wide adoption during the past 21 years has made it a target for attackers, so hardening your system properly is a must.
Additionally, in highly regulated markets, you must comply with specific operational requirements, proving that you conform to standards and even that you have included new mandatory authentication methods, such as two-factor authentication. In this ebook, I discuss SSH and how to configure and manage it to guarantee that your network is safe, your data is secure and that you comply with relevant regulations.Get the Guide