[wplug-plan] Program Suggestion
Robert Supansic
rsupansic at libcom.com
Tue May 7 10:40:18 EDT 2002
The following is a shell-script backup program which I wrote and have been using for the last
year on my office network and on a client's fileserver.
I do not know whether it is useful to anyone else, represents good programming practice, or
is the best way to provide a backup function. I do know that I fhave found it very useful and
that it works. From a pedgogical standpoint, it does raise a lot of issues involved with
backup up and may be a good candidate for a program for that reason.
Look the program over and let me know if I should prepare a talk.
Bob Supansic
! /bin/bash
# /backup/backup: performs full and incremental backups
# Usage: /backup/backup
# Uses: afio 2.4.6, cdrecord 1.8.1
# 11/26/2001 by r supansic
# Based on code by Rene Voorburg
# This program runs every day at 1:00 AM.
# On Saturdays, full backups are created and written to the CD.
# On the first Saturday of the month, the linux side is backed
# up; on all other Saturdays, the data side is backed up.
# On all other days, incremental backups are created and stored
# in the /backup directory.
BACKUP_DIR="/backup"
export BACKUP_LOG="$BACKUP_DIR/backup.log"
echo -e "---"$( date ) >> $BACKUP_LOG
BACKUP_FROM_1="/"
BACKUP_TO_1="$BACKUP_DIR/linux"
BACKUP_FROM_2="/win95"
BACKUP_TO_2="$BACKUP_DIR/win95"
BACKUP_FROM_3="/win95/progs"
BACKUP_TO_3="$BACKUP_DIR/win95"
BACKUP_FROM_4="/smb"
BACKUP_TO_4="$BACKUP_DIR/smb"
CDIMAGE="/usr/cd_image/backup"
CD_NAME="CyberDrv"
IMGMOUNT="/mnt"
# Mounts /dev/hda6 at /backup/linux, if not already mounted.
if [ -z "$( mount | grep $BACKUP_TO_1 )" ]
then
mount -t vfat /dev/hda6 "$BACKUP_TO_1" 2>>$BACKUP_LOG
fi
# Backup excludes named directories, removes leading slashes,
# and compresses files. Screen output and errors are written to
# $BACKUP_LOG.
cd /
if [ "$( date +%a )" = "Sat" ]
then
# Checks for presence of blank CD in drive; if not found, aborts.
if ! ( /backup/cdcheck )
then
echo -e "--No blank CD in drive; full backup aborted."\\n >> $BACKUP_LOG
cd "$OLDPWD"
exit
fi
# Gets CD device name.
CDEVICE=$( cdrecord -scanbus | grep "$CD_NAME" | cut -f2 )
# Creates the image file, creates ext2 filesystem in the image file,
# and mounts the image file preparatory to writing to it.
if ! ( dd if=/dev/zero of="$CDIMAGE" bs=1024k count=700 > /dev/null 2>&1 )
then
echo "--Exiting: could not create image file." >> $BACKUP_LOG
cd "$OLDPWD"
exit 1
fi
if ! ( mkfs -t ext2 -b 2048 -F "$CDIMAGE" > /dev/null 2>&1 )
then
echo "--Exiting: could not create ext2 filesystem." >> $BACKUP_LOG
cd "$OLDPWD"
exit 1
fi
if ! ( mount -t ext2 -o loop=/dev/loop1 "$CDIMAGE" "$IMGMOUNT" > /dev/null 2>&1 )
then
echo "--Exiting: could not mount image file." >> $BACKUP_LOG
cd "$OLDPWD"
exit 1
fi
FIRST_SAT=$( cal | grep " 1" | cut -b18- | tr -d " " )
if [ "$FIRST_SAT" == "$( date +%-d | tr -d " " )" ]
then
BACKUP_TYPE="Full afio system backup"
ARCHIVE_NAME=$IMGMOUNT/$( basename $BACKUP_TO_1 )".afio"
echo "--$BACKUP_TYPE of linux partition" >> $BACKUP_LOG
find "$BACKUP_FROM_1" \
-path /backup -prune -o \
-path /cdrom -prune -o \
-path /floppy -prune -o \
-path /lost+found -prune -o \
-path /mnt -prune -o \
-path /proc -prune -o \
-path /smb -prune -o \
-path /usr/cd_image -prune -o \
-path /var/cache/man -prune -o \
-path /var/lib/dosemu/bootdir.first -prune -o \
-path /win95 -prune -o \
-follow \! -type d -print > "$BACKUP_TO_1/flist" 2>/dev/null
cat "$BACKUP_TO_1/flist" | afio -o -Z "$ARCHIVE_NAME" 2>>$BACKUP_LOG
else
BACKUP_TYPE="Full afio data backup"
ARCHIVE_NAME=$IMGMOUNT/$( basename $BACKUP_TO_2 )".afio"
echo "--$BACKUP_TYPE of /win95 directories" >> $BACKUP_LOG
find "$BACKUP_FROM_2" \
-follow \! -type d -print > "$BACKUP_TO_2/flist" 2>/dev/null
cat "$BACKUP_TO_2/flist" | afio -o -Z "$ARCHIVE_NAME" 2>>$BACKUP_LOG
ARCHIVE_NAME=$IMGMOUNT/$( basename $BACKUP_TO_4 )".afio"
echo "--$BACKUP_TYPE of /smb directories" >> $BACKUP_LOG
find "$BACKUP_FROM_4" \
-follow \! -type d -print > "$BACKUP_TO_4/flist" 2>/dev/null
cat "$BACKUP_TO_4/flist" | afio -o -Z "$ARCHIVE_NAME" 2>>$BACKUP_LOG
fi
# Unmounts the image file, burns the CD, and deletes the image file.
umount "$IMGMOUNT"
cdrecord -eject speed=4 dev="$CDEVICE" -data "$CDIMAGE" 1>/dev/null
2>>"$BACKUP_LOG"
/backup/cdcheck
rm -f "$CDIMAGE"
else
if [ "$( date +%a )" = "Sun" ]
then
OLD_DATE='-2'
else
OLD_DATE='-1'
fi
ARCHIVE_NAME="day"$( date +%d )".afio"
BACKUP_TYPE="Incremental afio backup"
echo "--$BACKUP_TYPE of linux partitions" >> $BACKUP_LOG
find "$BACKUP_FROM_1" \
-path /backup -prune -o \
-path /cdrom -prune -o \
-path /floppy -prune -o \
-path /lost+found -prune -o \
-path /mnt -prune -o \
-path /proc -prune -o \
-path /smb -prune -o \
-path /var/cache/man -prune -o \
-path /var/lib/dosemu/bootdir.first -prune -o \
-path /win95 -prune -o \
-mtime "$OLD_DATE" \
-follow \! -type d -print > "$BACKUP_TO_1/flist" 2>/dev/null
cat "$BACKUP_TO_1/flist" | afio -o -Z "$BACKUP_TO_1/$ARCHIVE_NAME"
2>>$BACKUP_LOG
echo "--$BACKUP_TYPE of /win95/progs directories" >> $BACKUP_LOG
find "$BACKUP_FROM_3" \
-mtime "$OLD_DATE" \
-follow \! -type d -print > "$BACKUP_TO_3/flist" 2>/dev/null
cat "$BACKUP_TO_3/flist" | afio -o -Z "$BACKUP_TO_3/$ARCHIVE_NAME"
2>>$BACKUP_LOG
echo "--$BACKUP_TYPE of /smb directories" >> $BACKUP_LOG
find "$BACKUP_FROM_4" \
-mtime "$OLD_DATE" \
-follow \! -type d -print > "$BACKUP_TO_4/flist" 2>/dev/null
cat "$BACKUP_TO_4/flist" | afio -o -Z "$BACKUP_TO_4/$ARCHIVE_NAME"
2>>$BACKUP_LOG
fi
# Unmounts /backup/linux, if still mounted.
if ! [ -z "$( mount | grep $BACKUP_TO_1 )" ]
then
umount "$BACKUP_TO_1" 2>>$BACKUP_LOG
fi
# Log entry written.
LOG_ENTRY=$( date | cut -c11-20 )
echo -e "--All Backups completed $LOG_ENTRY"\\n >> $BACKUP_LOG
cd "$OLDPWD"
---
---
More information about the wplug-plan
mailing list