
Overview
During the original installation of the LFS system, it contained only a floppy, IDE hard disk, and IDE CD-ROM as long-term storage devices. A CD-RW drive was subsequently added to facilitate backups. This necessitated changes in the kernel, and to the method for loading the IDE CD driver. This is because if the IDE CD-ROM driver detects the IDE CD-RW device, it will load the driver for both CD-ROMs. This becomes a problem when attempting to load the SCSI CD emulation driver for the IDE CD-RW which is required to write to CD. As such, the IDE CD driver was moved to being loaded as a module, giving us the opportunity to exclude the IDE CD-RW drive from the set of devices recognized by the IDE driver (see /etc/modules.conf).
Once the devices are loaded properly, a procedure for backing up the server is required. This is handled through a combination of a backup script, the cdrtools package, and the fcron utility, installed from the BLFS book.
Setting up the Kernel and Modules
The following parameters were modified using make menuconfig to facilitate CD writing:
ATA/IDE/MFM/RLL support -->
IDE, ATA and ATAPI Block Devices -->
<M> Include IDE/ATAPI CDROM support
<M> SCSI emulation support (*)
SCSI support -->
<M> SCSI support
<M> SCSI CD-ROM support
<M> SCSI generic support
(*) This was originally set to <*> (compiled into the kernel). We change it to <M> to load as a module.
At this point, the kernel must be recompiled, as well as any modules that it will use. The new kernel image must be copied to the /boot directory, as well as the /usr/src/linux/System.map file. You will need to modify the /etc/lilo.conf file to recognize the new kernel image, and finally, lilo must be run.
The next step is to load the appropriate modules at boot time so they are always ready for use. I copied the /etc/rc.d/init.d/template file to /etc/rc.d/init.d/cddrivers. Following is the text of this file:
#!/bin/sh
# Begin $rc_base/init.d/cddrivers
source /etc/sysconfig/rc
source $rc_functions
case "$1" in
start)
echo "Starting CD ROM drivers..."
loadproc modprobe scd0
;;
stop)
echo "Stopping CD ROM drivers..."
rmmod ide-cd
rmmod sr_mod
rmmod ide-scsi
rmmod cdrom
rmmod scsi_mod
;;
restart)
$0 stop
sleep 5
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
# End $rc_base/init.d/cddrivers
Next, we need to execute this script. We do so by placing the appropriate link in the /etc/rc.d/rcsysinit.d/ directory (execute the following command from within /etc/rc.d/rcsysinit.d):
ln -s ../init.d/cddrivers S35cddrivers [Enter]
Note that there are no links to stop the drivers (rather, unload them) during system shutdown. The appropriate commands are in the cddrivers script in order to allow the administrator to manually unload the drivers, if desired. Otherwise, the drivers will unload automatically when the system is shut down.
At some point through the process of setting this up, the /dev/cdrom link disappeared. This will become evident when you try to mount the CD-ROM drive. To restore it, switch to the /dev directory, and execute the following command:
ln -s /dev/hdc cdrom [Enter]
This assumes that the IDE CD-ROM is still /dev/hdc.
The next step is to define how the modules load. This is easily done with the /etc/modules.conf file. The following statements are added to control this process:
options ide-cd ignore=hdd
alias scd0 sr_mod
pre-install sg modprobe ide-scsi
pre-install sr_mod modprobe ide-scsi
pre-install ide-scsi modprobe ide-cd
These tell the ide-cd driver to ignore the /dev/hdd device (the IDE/ATAPI CD writer). They then instruct the modprobe utility to load the modules in a specific sequence, and to allow the user to refer to the sr_mod device as scd0 (used in the startup script above).
At this point, you should be able to restart the server, log in, and display the appropriate loaded modules with the lsmod command.
The Backup Script
The backup script is available HERE. It is well commented, and provides sufficient information about what is going on at each step of the backup process. This section will cover more general aspects of the script.
Generally speaking, this backup script provides two types of backups, full and differential. The full backup is performed once per week, and the differentials are performed on the other 6 days. While it is less likely that changes will be made to the system on a weekend, it is possible, and should be accounted for. For scheduling information, see Configuring fcron to Automate the Backups below.
The script is divided into 5 general sections:
Of particular importance here is that the backup directory should be in a directory which does not get backed up. If you include this in the backup, each time you run a back up, you will be backing up the backup files (rather redundant, and wasteful of space). As such, the /tmp directory was chosen to store backup files; it does not appear in the list of directories to be backed up.
Section 2: Make sure everything is ready to go
This section insures that the appropriate directories have been set up, and that the CD-RW device is connected and ready to receive the image (although as of this writing, there is no error condition yet to insure that the media is loaded into the drive). If any of the required directories are missing, they will be created. We also delete all files in all directories right before running a full backup. This insures that there will be a single full backup on the full backup day, and differentials for each subsequent day until the next full backup day.
This section also checks for when the last full backup was run.
Section 3: Create the backup files
This section actually creates the compressed files containing the system's data. Each directory specified will have a distinct file created for it, as will the root (/) directory. In the event that a full backup is performed, the appropriate full backup date file will be updated.
Section 4: Move the files out to the CD Writer
This section takes all files for all days in the backup directory and copies them out to the CD-RW device. This is done in two steps. First the cd image is created and stored in the temporary backup directory. Note that this can take up a great deal of space at this stage. Once the image is created, its size is checked to insure that it will fit onto a CD-RW disc. Second, the image is copied to the CD-RW device. At each of the steps, we check the return values of the major commands (mkisofs... and cdrecord...) to insure that the command was executed successfully. If a failure was detected, we break out of the script to allow the administrator to fix the problem and continue.
Note that in order to insure that the cd image file will fit onto the CD-RW media, we use the stat utility to capture the image's file size. Stat does not come with, nor is it referenced by the LFS or BLFS manuals. This document has been included with details on installing stat.
Section 5: Clean up
Here we simply clean up any temporary files that were created and are no longer needed. At present, only the cd image is removed.
Configuring fcron to Automate the Backups
Typically, in the *nix world, cron is the standard scheduling utility. There are many such utilities. The BLFS book has included the fcron utility over cron, due to its extended capabilities, and backward compatibility with cron. Once fcron is installed and configured, it may be managed as such:
Type fcrontab -e at the shell prompt to edit the fcrontab (fcron table [of entries]) file. This will bring you to a screen where you may enter settings for a particular event. For more detailed information on how to make entries into this file, issue a man 5 fcrontab at the shell prompt.
There are a wide range of options for fcrontab entries. For the purposes of the backup, we will elect something simple. The format of the entry is as follows:
minute hour date month dayofweek command
where
minute is the minute, a value from 0 to 59
hour is the hour of the day on a 24-hour clock from 0 to 23
date is the numerical day of the month from 1 to 31
month the the numerical month number from 1 to 12
dayofweek is the day of the week from 0 to 7 (both 0 and 7 are Sunday)
command is the name of the command to be executed
Consider the following:
0 22 * * * backup.sh
This entry will execute the backup script backup.sh everyday of the week (and month and year) at 10:00 p.m. (22 hours and 0 minutes is 10:00 p.m.) This entry assumes that backup.sh is in the path (/usr/sbin should be in the path). If it is not, then you will need to modify the entry to indicate the full path to the backup.sh file:
0 22 * * * /directory/path/backup.sh
You can place comments into the fcrontab file be placing a '#' sign in front of them. It is common practice to place this character at the beginning of each comment line. For example:
# Run the backup script at 10:00 p.m. daily:
0 22 * * * backup.sh
To make the entries, you must place the editor into Insert mode. To do this, press the Insert key on the keyboard. During insert mode, you can add and delete all of the text you wish. Once you are done, you must press the Esc key to exit insert mode. Then, you may save the file by pressing
:wq [Enter]
When you press the ':' symbol, a colon will appear at the bottom of the screen. This means you are entering command mode. The 'w' means to write the file to disk, and the 'q' instructs the editor to quit. Once you save the changes to the file and quit, fcron automatically reads the changes, and updates its internal table to account for the changes. No restarting of anything is necessary. If you wish to quit without saving your changes, you can just press :q [Enter].
Using this strategy, and replacing the CD-RW media every Monday, you will have a CD for the previous week beginning with a full backup (created on Monday night), and a differential backup for each day after Monday for the week.
References
Linux System Administration:
LPI Linux Certification in a Nutshell by Jeffrey Dean. Published by O'Reilly
CD Writing on Linux (including driver information):
CD-Writing HOWTO. LinuxDocs.org
fcrontab Configuration:
fcron Home Page