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!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Chris Birchall's Re-Engineering Legacy Software (Manning Publications)
- The Italian Army Switches to LibreOffice
- Linux Mint 18
- ServersCheck's Thermal Imaging Camera Sensor
- Petros Koutoupis' RapidDisk
- Oracle vs. Google: Round 2
- The FBI and the Mozilla Foundation Lock Horns over Known Security Hole
- Privacy and the New Math
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide