-->
Page 339
This hour continues the discussion of basic system administration skills and shows you how to back up and restore your system by using several different Linux utilities (included on your CD-ROM). With a little effort, you'll be able to easily perform these system administration tasks.
There are several things you should consider before backing up or restoring your system. Although one ideal time to back up is after you've installed Linux and made sure all your devices (such as the sound card, graphics card, or tape drive) are working, there are other considerations. For example, if the kernel supplied on the CD-ROM works well for your system, then you can simply rely on the CD for your initial backup in case you have to do a full restore.
You should understand the difference between a backup and an archive. Backups are performed at regular intervals to save important documents, files, or complete systems.
Page 340
Archives are made to save important documents, files, or complete systems for long periods of time. This means that you should first devise a backup strategy and ask yourself the following questions:
You can answer some of these questions by looking at the way you use your Linux system. If you're just using Linux for word processing or running spreadsheets, you can probably get away with only backing up certain files or directories. If you're using Linux to learn programming, you'll want to keep not only original copies of your programs, but perhaps different versions. If you have other users on the system, you'll want to not only save copies of their directories, but the /etc/passwd file, or even the whole system, so that you can quickly restore the system in the event of a hard drive crash (unlikely) or system operator error (more likely).
The size of your system and the capacity of your hard drives or other storage devices may determine how to approach a backup strategy. If your Linux system is small enough (around 200MB), you can quickly back up everything to another hard drive or to a tape drive. You also can use a removable media drive, such as an Iomega Zip drive or Sysquest EZ-flyer. If you only have to save copies of a small number of small files, you may even be able to use high-density floppies for storage.
You'll probably decide on a combination of archiving and regularly scheduled full or incremental backups. You need to choose the software to use and explore how to automate as much of the process as possible, perhaps by using crontab entries (discussed in Hour 24, "Scheduling"). Whatever you do, when you decide on your strategy, stick to it! The worst time to create and use a backup strategy is after you run into problems or lose files.
Page 341
Although use of the tar command was discussed in Hour 5, "Manipulation and Searching Commands," as the system administrator, you'll want to explore some of the more complex tar command-line options and experiment with creating backups before implementing your backup strategy.
The tar command creates a tape archive. You can write the archive to your hard drive, a tape drive, or nearly any other Linux device. To create a quick backup of your users' home directories, use tar to create the archive. For example,
# tar cPfC users.tar / home
This command line creates the tape archive users.tar in the current directory. One easy way to regularly back up these directories is to save them on a different file system. If you have a DOS or Windows partition mounted (see Hour 21, "Handling Files"), automate the backup process with a crontab entry:
30 17 * * * root tar cPfC /mnt/dos/windows/desktop/users.tar / home
This entry, in the /etc/crontab file, backs up your users' directories at 5:30 p.m. each day and saves the archive in the Windows desktop folder. As you can see, automating the backup process isn't that hard, and has the benefit of working in the background without your attention; a process called an unattended backup. If you save your data on a separate file system, you can easily restore the files later by using the tar command's x, or extract, option:
# cd / # tar xvf /mnt/dos/windows/desktop/users.tar
These command lines restore your users' directories and files, starting at the / or root directory. While backing up files to another file on your hard drive is easy, you also can use the tar command with tape drives by specifying the tape device on the tar command line.
JUST A MINUTE |
Unfortunately, there are no utilities to format tapes under Linux. Although you must still use a DOS or Windows utility to do this, you won't have to bother with formatting if you make sure to purchase preformatted tapes. |
This hour doesn't detail all the ins and outs of installing or using different tape devices, but it does show you the general approach and some examples you may want to try. To use a tape drive with the tar command, you must find the tape device under the /dev directory. There are a number of them, but this section uses the general floppy tape driver, /dev/ftape, as an example.