The FreeBSD 'zine
March 2000 : Backups to CD

Backing up FreeBSD to CD
by Maurice Castro <[email protected]>

Introduction

David Lay's article in February reminded me of some code that I use to make archival backups of my home computer systems to CD. The following simple shell script uses dump, bzip, mkisofs and cdrecord to make dumps of your file-systems and copy them to a CD-Writer.

Preconditions

For reliable CD-ROM authoring, I find it useful to have either:

  • A separate partition of 2 GB; or,
  • Two separate partitions of 1 GB

for preparing the data to be written to the CD and storing the images produced by the premastering software. The example script provided below assumes that a single partition of 2GB sizes is available. On my system this area is called /build. Having a separate partition for this purpose ensures that it is always treated as a scratch area and hence does not have any permanent data in it that needs to be preserved as well as allowing the transfer to the CD-Writer to function at the the maximum rate.

Notes

Configuration:

  • The disks to be backed up are listed in DISKSTOBACKUP. This should be customized for your application.

  • DUMPOPT is currently set to update the /etc/dumpdates file. This is useful if you intend to do incremental backups.

  • DUMPLVL is currently set to do a full backup of any disks. This can be changed to perform an incremental backup instead.

Bzip is used instead of gzip as Bzip provides a better compression ratio. This is particularly significant when backing up to CD-ROMs as the media is quite small. With my file mixture bzip managed to compress 1.5GB of files into 600MB of space.

The summary file contains details of how and what is backed up. This is useful when restoring files as it allows the user to determine how they should be restored.

This script does not contain checking for error conditions. An improvement on the script would abort if the iso-image had zero length or if any of the dumps failed.

It is possible to rewrite the script to eliminate the holding of the ISO image, however, this optimization prevents cdrecord from determining the size of the image and having a chance to abort if the image will not fit on the disk.

Script

backuptocd

#!/bin/sh

# Configuration
HOLDDISK=/build
DISKSTOBACKUP=/:/var:/usr
DUMPLVL=0
DUMPOPT=u
SUMMARYFILE=summary
SPEED=4
SCSI="0,4,0"

# Programs
DF=/bin/df
SED=/usr/bin/sed
DUMP=/sbin/dump
ZIP=/usr/local/bin/bzip2
BASENAME=/usr/bin/basename
DATE=/bin/date
MKISOFS=/usr/local/bin/mkisofs
CDRECORD=/usr/local/bin/cdrecord

# Create hold dir
rm -fr $HOLDDISK/dump
mkdir -p $HOLDDISK/dump

# Create summary file
${DATE} > $HOLDDISK/dump/$SUMMARYFILE

# Figure out the names of the devices
DEVICESTOBACKUP=""
for i in `echo $DISKSTOBACKUP | ${SED} 's/:/ /g'`
do 
        DEV=`${DF} -k $i 2>/dev/null | \
		${SED} '/^Filesystem/{N;s/.*\n//;s/ .*//;p;};d'`
        DEVICESTOBACKUP="$DEVICESTOBACKUP $DEV"
        echo "$DEV ----> $i" >> $HOLDDISK/dump/$SUMMARYFILE
done

# Perform dumps
for i in $DEVICESTOBACKUP
do
        TODAY=`${DATE} "+%Y%m%d"`
        DEV=`${BASENAME} $i`
        echo "${DUMP} ${DUMPLVL}${DUMPOPT}f - $i | ${ZIP} -z9 \
		> $HOLDDISK/dump/$DEV.$TODAY.$DUMPLVL" \
		>> $HOLDDISK/dump/$SUMMARYFILE
        ${DUMP} ${DUMPLVL}${DUMPOPT}f - $i | ${ZIP} -z9 \
		> $HOLDDISK/dump/$DEV.$TODAY.$DUMPLVL
done

#create iso-image
$MKISOFS -R -l -L -T $HOLDDISK/dump > $HOLDDISK/dump.iso

# dump to cdrom
${CDRECORD} -v speed=${SPEED} dev=${SCSI} $HOLDDISK/dump.iso

# clean up
rm $HOLDDISK/dump.iso
rm -fr $HOLDDISK/dump

Restoring a dump

To selectively restore files generated using the script above:

  • cd mountpt
  • cat filename | bzip2 -d | restore -if -

Conclusion

This script has proved useful for backing up my home systems. It is likely that it will reach its limits in a few more months at which time I will have to look into a mechanism for splitting files across media. However, in the meantime it provides some peace of mind, knowing that my systems are backed up.

Current Issue
. Issue #05 : June 2000

Old Issues
. Issue #01 : February 2000
. Issue #02 : March 2000
. Issue #03 : April 2000
. Issue #04 : May 2000

Quick Links
. Table of Contents
. Mailing Lists
. FreeBSD Events
. User Group Calendar
. Site Statistics
. Old Articles
. Latest News
. Press Releases
. Contribute
. Send us Feedback
. Other Resources
. Submit an Article
. Submit an Event

Today's Fortune
"The chain which can be yanked is not the eternal chain." -- G. Fitch

FreeBSD 'zine Poll
Are you going to BSDCon?
Yes.
No.
Maybe.
What the hell is BSDCon?
Results More polls

Sponsors
. VicFUG

Download
. Issue #01 : Download
. Issue #02 : Download
. Issue #03 : Download
. Issue #04 : Download
. Issue #05 : Download

Search

Runs on FreeBSD

Add Channel to My Netscape

DaemonNews

Contact: <[email protected]>
This site and the tarballs are built every 6 hours.
Copyright � 1998-2000, The FreeBSD 'zine
Code revision: 06/15/2000��All rights reserved.