Using Backup Software

 < Day Day Up > 

Because there are thousands of unique situations requiring as many unique backup solutions, it comes as no surprise that Linux offers many backup tools. Fedora Core provides the classic command-line backup software tar, dump, and cpio. The following sections discuss each of those tools and examine how dd and cp commands can be used to copy files. (Those copies can be considered backups if you store them safely.) Fedora Core provides a graphical interface for tar named Kdat that exploits the KDE desktop's drag-and-drop functionality. Fedora Core Linux also provides a graphical archiving tool, File Roller, that can create and extract files from archives. Finally, Fedora Core provides support for the Amanda backup application a sophisticated backup application that works well over network connections and can be configured to automatically back up all the computers on your network. Amanda works with drives as well as tapes. The book Unix Backup and Recovery by W. Curtis Preston includes a whole chapter on setting up and using Amanda, and this chapter is available online at http://www.backupcentral.com/amanda.html.

NOTE

The software in a backup system must support the hardware, and this relationship can determine which hardware or software choices you make. Many sysadmins choose a particular backup software not because they prefer it to other options, but because it supports the hardware they own.

The price seems right for free backup tools, but consider the software's ease of use and automation when assessing costs. If you must spend several hours implementing, debugging, documenting, and otherwise dealing with overly elaborate automation scripts, the real costs go up.


tar: The Most Basic Backup Tool

The tar tool, the bewhiskered old man of archiving utilities, is installed by default. It is an excellent tool for saving entire directories full of files. For example, here is the command used to back up the /etc directory:

 # tar cvf etc.tar /etc 

Here, the options use tar to create an archive, be verbose in the message output, and use the filename etc.tar as the archive name for the contents of the directory /etc.

Alternatively, if the output of tar is sent to the standard output and redirected to a file, the command appears as follows:

 # tar cv /etc > etc.tar 

and the result is the same.

All files in the /etc directory will be saved to a file named etc.tar. With an impressive array of options (see the man page), tar is quite flexible and powerful in combination with shell scripts. With the -z option, it can even create and restore gzip compressed archives while the -j option works with bzipped files.

TIP

Do you have backup tapes made with MTF that you would like to extract a file from? The Microsoft Tape Format is used to back up Windows NT files and can be read with a Linux utility named mtf.

This Linux program works with SCSI tape drives. Software compression and archives that span tapes are not yet supported. Download the source code from http://www.layton-graphics.com/mtf/.


Creating Full and Incremental Backups with tar

If you want to create a full backup,

 # tar cjvf fullbackup.tar.bz2 / 

will create a bzip2 compressed tarball (the j option) of the entire system.

To perform an incremental backup, you must locate all the files that have been changed since the last backup. For simplicity, assume that you do incremental backups on a daily basis. To locate the files, use the find command:

 # find / -newer name_of_last_backup_file ! -a  type f  print 

When run alone, find will generate a list of files systemwide and print it to the screen. The ! -a -type eliminates everything but regular files from the list; otherwise, the entire directory would be sent to tar even if the contents was not all changed.

Pipe the output of our find command to tar as follows:

 # find / -newer name_of_last_backup_file !  type d -print |\  tar czT - backup_file_name_or_device_name 

Here, the T - option gets the filenames from a buffer (where the - is the shorthand name for the buffer).

NOTE

The tar command can back up to a raw device (one with no file system) as well as a formatted partition. For example,

 # tar cvzf /dev/hdd  /boot  /etc /home 

backs up those directories to device /dev/hdd (not /dev/hda1, but to the unformatted device itself).

The tar command can also back up over multiple floppy disks:

 # tar czvMf /dev/fd0 /home 

will back up the contents of /home and spread the file out over multiple floppies, prompting you with this message:

 Prepare volume #2 for `/dev/fd0' and hit return: 


Restoring Files from an Archive with tar

The xp option in tar will restore the files from a backup and preserve the file attributes as well, and tar will create any subdirectories it needs. Be careful when using this option because the backups might have been created with either relative or absolute paths. You should use the tvf option with tar to list the files in the archive before extracting them so that you will know where they will be placed.

For example, to restore a tar archive compressed with bzip2,

 # tar xjvf fedoratest.tar.bz2 

To list the contents of a tar archive compressed with bzip2,

 # tar tjvf fedoratest.tar.bz2 drwxrwxr-x paul/paul         0 2003-09-04 18:15:05 fedoratest/ -rw-rw-r-- paul/paul       163 2003-09-03 22:30:49                            ¬fedoratest/fedora_screenshots.txt -rw-rw-r-- paul/paul       840 2003-09-01 19:27:59                            ¬fedoratest/fedora_guideline.txt -rw-rw-r-- paul/paul      1485 2003-09-01 18:14:23 fedoratest/style-sheet.txt -rw-rw-r-- paul/paul       931 2003-09-01 19:02:00 fedoratest/fedora_TOC.txt 

Note that because the pathnames do not start with a backslash, they are relative pathnames and will install in your current working directory. If they were absolute pathnames, they would install exactly where the paths state.

Backing Up Files with cpio

The cpio tool (installed by default) is great for saving individual files scattered throughout a file system as opposed to all the files that are located in a single directory. You can generate a list of files and pipe them to cpio; those files then become part of the archive.

Interestingly, RPM files (Red Hat Package Manager) are modified cpio files. The rpm2cpio command can be used to unpack (rather than install) RPM files if needed; refer to Chapter 7 for more information on RPM files.

Create a cpio Archive

To see how cpio works, you can create a list of files from the /etc directory and then use that list to create the cpio archive:

 # find /etc -print > filelist # cat filelist | cpio -o > backup.cpio 

To do it all on one line (Unix people like to do that), try this:

 # find /etc -print | cpio -o > backup.cpio 

Note that you can concatenate several file lists together and use grep to search for and remove files you do not want in the archive. (Using cat and grep are covered in Chapter 5, "First Steps with Fedora.") You can use these basic commands to build scripts (refer to Chapter 14, "Automating Tasks") that can perform complex and elaborate backups tailored to your particular needs; such is the power of the GNU tools provided with Linux. The man page for cpio lists an impressive array of options for backing up and restoring files.

NOTE

You can name your backups anything you want, but it is a good idea to follow the filename conventions of using the .tar, .tgz, and .cpio extensions, for example. Also, include the current date and time in the filename easily done when using shell scripts and cron to perform backups. (Refer to Chapter 14 for examples of shell scripting.)


Restoring Files from an Archive with cpio

The -im option in cpio will restore the files from a backup and preserve the file attributes as well. Whereas tar will create any subdirectories it needs, the -d option needs to be explicitly added to cpio for the same result. Be careful because the backups might have been created with relative or absolute paths. You should use -otv with cpio to list the files in the archive before extracting them so that you will know where they will be placed.

To restore a cpio archive,

 # cpio -imd fedoratest.cpio 

To list the contents of a cpio file,

 # cpio -otv fedoratest.cpio drwxrwxr-x paul/paul         0 2003-09-04 18:15:05 fedoratest/ -rw-rw-r-- paul/paul       163 2003-09-03 22:30:49                            ¬fedoratest/fedora_screenshots.txt -rw-rw-r-- paul/paul       840 2003-09-01 19:27:59                            ¬fedoratest/fedora_guideline.txt -rw-rw-r-- paul/paul      1485 2003-09-01 18:14:23 fedoratest/style-sheet.txt -rw-rw-r-- paul/paul       931 2003-09-01 19:02:00 fedoratest/fedora_TOC.txt 

Note that because the pathnames do not start with a backslash, they are relative pathnames and will install in your current working directory. If they were absolute pathnames, they would install exactly where the paths state.

NOTE

Two of the oldest and most primitive Unix applications are the dump and restore commands. dump examines files on an ext2 and ext3 file system and determines which files need to be backed up. The backups can span multiple media and levels (dump levels determine the amount of data to be backed up). The dump archives are restored using the restore program. You can use restore across a network and use it to restore full and incremental backups. These bare-metal Unix applications are feature-rich but awkward to use, even for some Unix old-timers; for that reason, we do not cover their use in this chapter. Most users prefer the simpler GUI network backup utilities, such as those you learn about in "Alternative Backup Software," later in this chapter, or prefer to use tar.


The GNOME File Roller

The GNOME desktop file archiving graphical application File Roller (file-roller) will view, extract, and create archive files using tar, gzip, bzip, compress, zip, rar, lha, and several other compression formats. Note that File Roller is only a front-end to the command-line utilities that actually provide these compression formats; if they are not installed, File Roller cannot use that format.

CAUTION

File Roller will not complain if you select a compression format that is not supported by installed software until after you attempt to create the archive. Install any needed compression utilities first.


File Roller is well-integrated with the GNOME desktop environment to provide convenient drag-and-drop functionality with the Nautilus file manager. To create a new archive, select Archive, New to open the New Archive dialog box and navigate to the directory where you want the archive to be kept. Type your archive's name in the Selection: /root text box at the bottom of the New Archive dialog box. Use the Archive type drop-down menu to select a compression method. Now, drag the files that you want to be included from Nautilus into the empty space of the File Roller window, and the animated icons will show that files are being included in the new archive. When you are done, a list of files will be shown in the previously blank File Roller window (see Figure 16.1). To save the archive, simply select Archive, Close. Opening an archive is as easy as using the Archive, Open dialog to select the appropriate archive file.

Figure 16.1. Drag and drop files to build an archive with the GNOME File Roller.


The KDE Archiving Tools (KDE ark and kdat)

Fedora Core provides you with the KDE ark and kdat GUI tools for backups; they are installed only if you select the KDE desktop during installation. Archiving has traditionally been a function of the system administrator and not seen as a task for the individual user, so no elaborate GUI was believed necessary. Backing up has also been seen as a script driven, automated task in which a GUI is not as useful.

The KDE ark Archiving Tool

You launch ark by launching it from the command line. It is integrated with the KDE desktop (like File Roller is with GNOME), so it might be a better choice if you use KDE. This application provides a graphical interface to viewing, creating, adding to, and extracting from archived files as shown in Figure 16.2. Several configuration options are available with ark to ensure its compatibility with MS Windows. You can drag and drop from the KDE desktop or Konqueror file browser to add or extract files, or you can use the ark menus.

Figure 16.2. Here, the contents of a .zip file containing the screenshots used for Chapter 7 are displayed.


As long as the associated command-line programs are installed, ark can work with tar, gzip, bzip2, zip, and lha files (the latter four being compression methods used to save space by compaction of the archived files).

Existing archives are opened after launching the application itself. You can add files and directories to the archive or delete them from the archive, as shown in Figure 16.3. After opening the archive, you can extract all of its contents or individual files. You can also perform searches using patterns (all *.jpg files, for example) to select files.

Figure 16.3. The opening view of ark presented as a simple GUI browser. Here, several files are being selected to add to the new archive.


Choosing New from the File menu creates new archives. You then type the name of the archive, providing the appropriate extension (.tar, .gz, and so on), and then proceed to add files and directories as you desire.

Using the dd Command for Archiving

Although the dd command is not normally thought of as an archiving tool, it can be used to mirror a partition or entire disk, regardless of the information either contains. dd is useful for archiving copies of floppy disks while retaining the capability to restore the data to a floppy intact. For example,

 # dd if=/dev/fd0 of=floppyimage1.img 

Swapping the if= and of= values reverses the process. Although best known for copying images, dd can also be used to convert data, and it is especially useful when restoring older archives or moving data between big endian and little endian systems. Although such esoteric details are beyond the scope of this chapter, remember dd if you need to convert data from obsolete formats.

CAUTION

Do not confuse the if= and of= assignments; if you do, dd will be more than happy to overwrite your valid data with garbage. Use the Carpenter's Rule: "Measure twice cut once."


Using the Amanda Backup Application

Provided with Fedora Core, Amanda is a powerful, network backup application created by the University of Maryland at College Park. Amanda is a robust backup and restore application best suited to unattended backups with an autoloading tape drive of adequate capacity. It benefits from good user support and documentation.

Amanda's features include compression and encryption. It is intended for use with high-capacity tape drives, floptical, CD-R, and CD-RW devices.

Amanda uses GNU tar and dump; it is intended for unattended, automated tape backups, and is not well-suited for interactive or ad hoc backups. The support for tape devices in Amanda is robust, and file restoration is relatively simple. Although Amanda does not support older Macintosh clients, it will use Samba to back up Microsoft Windows clients, as well as any Unix client that can use GNU tools (which includes Mac OS X). Because Amanda runs on top of standard GNU tools, file restoration can be made using those tools on a recovery disk even if the Amanda server is not available. File compression can be done on either the client or server, thus lightening the computational load on less powerful machines that need backing up.

CAUTION

Amanda does not support dump images larger than a single tape and requires a new tape for each run. If you forget to change a tape, Amanda continues to attempt backups until you insert a new tape, but those backups will not capture the data as you intended them to. Do not use too small a tape or forget to change a tape, or you will not be happy with the results.


There is no GUI interface for Amanda. Configuration is done in the time-honored Unix tradition of editing text configuration files located in /etc/amanda. The default installation in Fedora Core includes a sample cron file because it is expected that you will be using cron to run Amanda regularly. The client utilities are installed with the package am-utils; the Amanda server must be obtained from the Amanda website. As far as backup schemes are concerned, Amanda calculates an optimal scheme on-the-fly and schedules it accordingly. It can be forced to adhere to a traditional scheme, but other tools are possibly better suited for that job.

The man page for Amanda (the client is amdump) is well written and useful, explaining both the configuration of Amanda as well as detailing the several programs that actually make up Amanda. The configuration files found in /etc/amanda are well commented; they provide a number of examples to assist you in configuration.

The program's home page is http://www.amanda.org. There, you will find information on subscribing to the mail list, as well as links to Amanda-related projects and a FAQ.

Alternative Backup Software

The free download version of Fedora Core does not provide any other sophisticated backup applications, but the version targeted to businesses usually does. Commercial and other freeware backup products do exist; BRU and Veritas are good examples of effective commercial backup products. Here are some useful free software backup tools that are not installed with Fedora Core Linux:

  • flexbackup This backup tool is a large file of Perl scripts that makes dump and restore easier to use. flexbackup's command syntax can be accessed by using the command with the -help argument. It also can use afio, cpio, and tar to create and restore archives locally or over a network using rsh or ssh if security is a concern. Its home page is http://www.flexbackup.org/.

  • afio This tool creates cpio-formatted archives, but handles input data corruption better than cpio (which does not handle data input corruption very well at all). It supports multi-volume archives during interactive operation and can make compressed archives. If you feel the need to use cpio, you might want to check out afio at http://freshmeat.net/projects/afio/.

  • cdbackup Designed for the home or small office user, cdbackup will work with any backup and will restore software that can read from stdin, write to stdout, and can handle linear devices such as tape drives. It makes it easier to use CD-Rs as the storage medium. Similar applications are available elsewhere as well; the home page for this application is at http://www.muempf.de/index.html.

Many other alternative backup tools exist, but covering all of them is beyond the scope of this book. Two good places to look for free backup software are Freshmeat (http://www.freshmeat.net) and Google (http://www.google.com/linux).

     < Day Day Up > 


    Red Hat Fedora 4 Unleashed
    Red Hat Fedora 4 Unleashed
    ISBN: 0672327929
    EAN: 2147483647
    Year: 2006
    Pages: 361

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net