13.3. Backup

13.3.1. Why backup?

Backing up your system is the only means of being able to repair it if it suffers severe damage, if you accidentally delete some important system files, or if someone breaks into your system and intentionally deletes some files. You should also backup your daily use data (compressed audio, images, office documents, e-mails, address book, etc.) to be safe.

You should make your backups using an appropriate medium and keep them in a safe place. Such a place should be outside the place you usually work in, if possible. You can even have two backups, one in place, and one outside. Generally speaking, you should make sure that you will be able to restore those backups if you want all this to be really useful.

13.3.2. Preparing your system

You probably have everything you need already installed in your system. You should also keep a boot disk near at hand (you made one, didn't you?). Actually, you can make backups using only tar and a compression tool such as gzip or bzip2. See an example in Backup example using TAR.

As an alternative, you can use specialized backup programs, such as Taper, Time Navigator, etc.

13.3.3. What to backup

Well, this might be the single most difficult question every system administrator asks her/himself when the time to backup comes. The answer to it depends on things such as: are you just backing up your personal data, your config files, or your whole system? How much time and/or space is it going to take? Will you be restoring your backup on the same machine/OS version, or on a different one?

Since this is a troubleshooting guide, we will try to focus on doing a backup that will allow us to quickly restore our system to the state it was before that terrible thing that rendered it unusable happened. Of course, you will need to make a backup of your personal data if you don't want to loose it, but... that is another story.

As a rule of thumb, you will need to backup the following directories: /etc, /home, /root and /var. If you do a complete backup of these directories, you will have saved not only your configurations, but your data as well (in case you are wondering where your data is, it is in the /home/your_user_name/ directory). Please bear in mind that this can take a long time to complete, but it is the safest bet.

A more sophisticated scheme would be to backup only the configuration files that have changed, leaving alone the ones that have not changed. This will take more "planning" time, but will lend to quicker backups (and quicker restores, too) and to backups that are "easier" to port from one machine/OS version to another.

Next, you will be presented with a list of the files you should pay the most attention to. Note that these lists are not exhaustive at all, especially if you have made lots of changes to your system[1]

In the directory /etc:

/etc/lilo.conf

Holds LILO's boot loader configuration. If you use grub instead of LILO, the files to backup are the ones in the directory /boot/grub.

/etc/fstab

Holds the disks partition table configuration and the associated mount points.

/etc/modules.conf

Holds the modules to load and their parameters according to your system's hardware. This might not be useful if restoring on a very different machine, but it might have some hints anyway.

/etc/isapnp.conf

Holds ISAPnP's settings if you use this to configure your ISA Plug & Play hardware.

Note

With kernel 2.4.x you might not need this file anymore, since plug'n'play hardware is configured using the DevFS file system.

/etc/X11/XF86Config

Holds X's settings. X is the graphical core of GNU/Linux and all its desktop environments and window managers.

/etc/cups

Holds cups's settings. cups is Mandrake Linux's default printing system.

/etc/printcap

If you do not use cups and you use the lpr printing system then you must backup this one instead of /etc/cups for your printer settings.

/etc/bashrc

Sets the bash shell systemwide configuration.

/etc/profile

Sets the system environment and some programs that are executed upon system startup.

/etc/crontab

Sets the cron jobs to be executed periodically, for system maintenance tasks for example.

/etc/rc.d/*

Sets the various runlevels of the system. Usually you will not need to backup these ones, but if you have added some personalized runlevels or changed a default one, you will need to back these up.

/etc/inittab

Sets the default runlevel your system will start with.

/etc/ssh

Keeps ssh settings. If you do secure remote access this file is very important to keep.

If you have a web server, an FTP server, or other servers, make a backup of their respective configuration files too.

In the directory /root and each user's home directory /home/user_name, the following directories:

~/.gnome/*

Settings for the GNOME desktop environment.

~/.kde/*

Settings for the KDE desktop environment.

~/.netscape/*

Settings for Netscape's family of programs. Navigator's bookmarks, Messenger's mail filters, etc.

~/.nsmail/*

Holds all your e-mail and newsgroups messages. You definitely do not want to loose these ones, do you?

~/Mail/*

If you use kmail this directory holds all your e-mail messages. You definitely do not want to loose these ones, do you?

~/.ssh/*

Holds personalized settings for ssh usage. If you use ssh, backup this one...

You also want to keep an eye on the following files:

~/.bash_profile

Holds environment variables, aliases, and more settings for the bash shell.

~/.bashrc

More bash settings.

~/.cshrc

Holds environment variables, aliases, and more settings for the CSH shell.

~/.tcshrc

Holds environment variables, aliases, and more settings for the tcsh shell.

Please note that we did not mention every single possible configuration file because we would need to write a whole book on that subject. For example, if you do not use netscape you need not backup netscape related files and directories, if you do not use ssh you need not backup ssh related stuff, and so on.

Summarizing, backup all of the configuration files of the programs you use and all of the configuration files you have changed. Also backup all your personal (and your system's users) data files. You will not regret it, trust me.

13.3.4. Where to backup?

The other big question to answer. This depends on how much do you want to backup, how fast do you want to make your backups, how easy is the access to the backup media, and a large list of etceteras.

Generally speaking, you need media that is at least as large as the amount of information you want to backup, and fast enough so the whole process will not take forever to complete.

13.3.5. Backup media

Next, we will provide you with a brief description of available backup media options. These vary in capacity, reliability, and speed. They are not given in any particular order, just as they come to mind. Please note that your backup software may or may not support all of them.

Note

This list is not intended to be an exhaustive analysis of the different storage media available out there. In fact, some of the things written below might change in the future. Things such as expected media life were taken from the manufacturer's web sites and/or personal and community experience. Also, there might be many personal points of view on many matters such as price or speed, for example.

Floppy Disk

Its capacity goes up to 1.44 MB[2]. They are easy to carry around but for today's needs they may not have enough room. Best way to carry small files. Slow. Cheap. Standard floppy disk drive in virtually every computer. Read/Write. Expected media life is 4 or 5 years.

Note

Please bear in mind that floppy disks are not too reliable.

LS120 Floppy Disk

Its capacity is 120 MB. Identical physical dimensions than floppy disks but with almost ten times more the capacity. Not so cheap. Needs a special floppy disk drive but this drive can also read/write standard floppy disks. Might be a good floppy replacement but it's speed lags behind that of ZIP drives. Read/Write. Expected media life is more or less the same than that of ZIP drives.

ZIP Disk

Its capacity goes up to 250 MB. Although not as thin as floppy disks, they are easy to carry around, too, and are more fit for today's needs. Good balance of features, although it may be a little expensive. Read/Write. Expected media life is 10 years for 100 MB units, maybe more for 250 MB units.

CD-R

Its capacity goes up to 700 MB these days, although the standard is 650 MB. Very cheap and reliable media. Today many argue that its capacity is not enough, but, hey, 650 MB sounds fine to me. Its strongest feature is that almost every computer on earth has a CD-ROM drive, so they can be read almost everywhere. Write only once. Read as many as you want (well, actually, as you can...). Expected media life is 20 years, maybe more if they are stored in a safe place and read not too often.

CD-RW

Same considerations as for CD-R, but it can be formatted and re-written as many as 1000 times. All in all cheap and reliable media. Expected media life is 15 years, maybe more if they are stored in a safe place and read not so often.

Tape

Its capacity goes from 120 MB (anyone has tape drives this old?) up to several gigabytes. Expensive and not very reliable media (hey, they are magnetic tapes after all). Even so, their capacity makes them ideal to backup servers and the like; if you want to backup your whole disk drive in only one piece of media, tape is the only way to go (at least, for now...). Its biggest drawback is that tape access is sequential, and this has a big performance impact, but SCSI tape drives are fast enough for today's needs and, hey, they do have many gigabytes of room to store your files. Read/Write. Expected media life is up to 30 years for new tape technologies.

Hard Disk

You might be wondering: Has this guy had whiskey for breakfast? No, I have not had whiskey for breakfast, it's just that today's disk prices have dropped in such a way that they might be considered seriously as a backup medium, too. They are relatively cheap, have huge room (up to 100 GB at the moment of writing this manual), are very reliable and the fastest of all media introduced in this list. If you have a laptop system this may not be an option[3], but on your desktop systems adding a spare disk drive just for backup purposes might be a good choice. Actually, you might not even need to add a new hard disk and do backups on the only hard disk you have; but this might not prove to be a good idea since it will not protect you from a hard disk crash.

Other removable media

Other removable media exist (Castlewood's ORB, and IOMEGA's JAZ come to mind) that have good price/features balance and are suited for doing backups. Some were even publicized as "hard disk replacements" (JAZ for example), but when used as hard disks they might not last too long due to design constraints (They are not hard disk drives). Anyway, Your Mileage May Vary on these matters, just make sure you choose wisely (with common sense) according to your needs, and ... good luck!

Remote directories

Well, this might not be considered strictly as "media", but we will say a little about it because it is a good backup choice if you do not have hundreds of megabytes to backup.

If your ISP provides you with some space you can use that space to place your files along with your web pages. You can find on the web many offerings for online remote storage services. If you have a network with two or more machines you can do backups on some "remote" machine on the network (other than the one you are trying to backup, of course...)

Actually, doing "remote" backups could be a security hole, so do not keep your top secret nor your most important files remotely backed up. Think that, in case of a major system failure, maybe you cannot even connect to that remote site to recover the files...

Please bear in mind that you can also combine backup medium according to your backup strategy, for example: tapes and CD-R, hard disk and tapes, hard disk and CD-R, etc.

13.3.6. When to backup?

There are many policies for backup schedules. Here we will introduce you to a few. Please, bear in mind that these are not mandatory, nor the best ones, nor the only ones. These are just guidelines you may want to follow in rolling out your own backup schedule.

There are many backup strategies out there, they depend on the media you use, on how often does your data change, and on how critical that data is to you or your organization. For example, one strategy states that you should make a full backup each weekend, and an incremental (changed stuff only) backup every day; then make a full backup every month and store that one in at least two places. This strategy might prove useful for an enterprise, but not for a personal computer. For your personal backups you can think of something like this: make a weekly backup of your files on your disk drive and each month transfer those backups to CD-R or tape.

13.3.7. Backup example using TAR

Next, we will introduce you to a little backup script that uses tar for making a complete backup of your home directory.

Warning

You need read permissions on the files, and read and execute permissions on directories, you are going to backup, otherwise the backup operation will fail.

#!/bin/bash

# Create a compressed backup of your home directory in a file named
# backup.tar.gz or backup.tar.bz2 depending on the compression scheme used.

BACKUP_DIRS=$HOME

# Uncomment the following line if you want GZipped backups
#tar cvzf backup.tar.gz $BACKUP_DIRS

# We do a BZipped backup here...
tar cvjf backup.tar.bz2 $BACKUP_DIRS
As you can see this is a very simple backup script that only does a backup of your home directory and puts the result into the very same directory. Let's enhance it a little...

#!/bin/bash

# Create a compressed backup of all the directories specified and put the
# resulting file in a directory of our choice.

BACKUP_DIRS="$HOME /etc /etc/rc.d"
BACKUP_FILENAME=`date`+%b%d%Y
BACKUP_DEST_DIR=$HOME

# Uncomment the following line for GZipped backups, comment for BZipped backups
#tar cvzf $BACKUP_DEST_DIR/$BACKUP_FILENAME.tar.gz $BACKUP_DIRS

# We do a BZipped backup here...
# Comment the following line for GZipped backups, uncomment for BZipped backups
tar cvjf $BACKUP_DEST_DIR/$BACKUP_FILENAME.tar.bz2 $BACKUP_DIRS
As you can see in this last example, we have added some more directories to our backup, and we have used a naming scheme to add the date of the backup to the resulting filename.

Of course, you can later move the resulting tar.bz2 or tar.gz file to any media you want. You can even backup directly to the media you want by mounting it and changing the variable BACKUP_DEST_DIR of the script accordingly. Feel free to enhance this script and make it as flexible as you want.

To restore the backups made this way, please look at Restore example using TAR

Notes

[1]

If you have made lots of changes, you probably won't need these lists anyway.

[2]

Well, actually they can be formatted at up to 1.92 MB using programs like SuperFormat and your standard floppy disk drive, but that's another story...

[3]

If you have a relatively new laptop, you may have space to put inside a second hard disk. Also, using USB or parallel port, you can attach external USB or parallel hard disk drives.


Tux on Star from MandrakeSoft Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
Unless otherwise stated, all the content of these pages and all images are Copyright MandrakeSoft S.A. and MandrakeSoft Inc. 2001.
http://www.mandrakelinux.com/