#!/bin/sh
# Title: full_backup
# Author: B. Alcock <alcockba@boat.bt.com>
# Last updated: Fri 27/02/1998

# Set the path for the script
PATH=/usr/ucb:/usr/bin:/usr/sbin:/usr/local/bin

# Tape device
TAPE_DEV=/dev/rmt/0mb

# Log file
# Set to blank for no logging 
LEVEL1=/var/adm/tape_log
LEVEL2=/var/adm/tape_log.2

# Which directories/files NOT to backup
EXCLUDE_FILES="
	/etc/.name_service_door
	/etc/.syslog_door
	/var/adm/tape_log
	/var/adm/tape_log.2
	"

# Which 'cpio' command to use
CPIO=/usr/bin/cpio


################################################
## NO USER SERVICABLE PARTS BELOW THIS POINT  ##
################################################

# Set where to log to
if [ "$LEVEL1" = "" ] ; then
	LEVEL1=/dev/null
fi

if [ "$LEVEL2" = "" ] ; then
	LEVEL2=/dev/null
fi

# So the log definitely knows who we are
LOGNAME=`whoami`

# Log the start of the backup
echo "$0: started ["`date`"] [user=$LOGNAME]" >>$LEVEL1

# File containing a list of files to backup
FILE_LIST=/tmp/filelist.$$

# Find all files except the non-real files
/usr/ucb/echo -n "" >$FILE_LIST
find / 	-path '/dev' -prune -o		\
	-path '/proc' -prune -o		\
	-path '/devices' -prune -o	\
	-path '/tmp' -prune -o		\
	-path '/var/tmp' -prune -o	\
	-print				\
	>>$FILE_LIST 2>/dev/null

# Make exlude file
echo $EXCLUDE_FILES |  awk '{ for (i=1; i<=NF; i++) { print $i } }' >$FILE_LIST.exclude

# Also remove the excluded files
/usr/xpg4/bin/grep -x -v -f $FILE_LIST.exclude $FILE_LIST >$FILE_LIST.2
# mv -f $FILE_LIST.2 $FILE_LIST

# Start the backup to tape
cd /
# cat $FILE_LIST | $CPIO -ov -O $TAPE_DEV >>$LEVEL2 2>>$LEVEL1

# Start testing the integrity and report results
echo "$0: testing ["`date`"] [user=$LOGNAME]" >>$LEVEL1
#if $CPIO -idvt -I $TAPE_DEV >>$LEVEL2 2>>$LEVEL1 ; then
#	echo "$0: completed successfully ["`date`"] [user=$LOGNAME]" >>$LEVEL1
#	exit 0
#else
#	echo "$0: error(s) occured on test ["`date`"] [user=$LOGNAME]" >>$LEVEL1
#	exit 1
#fi
