echo "==========================================================" |tee -a $LOG
echo "Beginning level $LEVEL backup of the following" |tee -a $LOG
echo "clients: $CLIENTS" |tee -a $LOG
echo "This backup is going to $SERVER:$DEVICE" |tee -a $LOG
echo "and is being logged to $SERVER:$LOG" |tee -a $LOG
echo "==========================================================" |tee -a $LOG
#LOGDIR will get lots of logs during this backup that you can use to check
#status. Each file system gets a separate log, and each host gets two logs,
#the one for this backup, and a running log for history purposes
BACKUPHOME=/var/log
[ -d $BACKUPHOME ] || mkdir $BACKUPHOME
Log_err $? "Could not verify or create $BACKUPHOME: $LOG" exit
LOGDIR=${BACKUPHOME}/backuplogs
[ -d $LOGDIR ] || mkdir $LOGDIR
Log_err $? "Could not verify or create $LOGDIR: $LOG" exit
#The script will now take the list of servers to back up, and check their
#"fstab" files, and create its own list of file systems to back up.
#It can also support being given a special list to use from the command
#line.
echo | tee -a $LOG
echo "Querying clients to determine which file systems to back up..." \
|tee -a $LOG
echo | tee -a $LOG
for INCLUDE_HOST in $CLIENTS
do
#Zero out these values, because we check them for that
CLIENT= ; FILE_SYS=
#Allow for "Partial" feature.
#User can list hostname:/file_system on the command line, instead of
#just the hostname. If that is done, only that file system will be
#backed up on that host
if [ -n "`echo $INCLUDE_HOST|grep ':' `" ] ; then
CLIENT=`echo $INCLUDE_HOST|awk -F: '{print $1}'`
FILE_SYS=`echo $INCLUDE_HOST|awk -F: '{print $2}'`
else
CLIENT=$INCLUDE_HOST
fi
export CLIENT FILE_SYS
Check_if_client_is_remote
# Get name of client operating system and version
if [ -n "$RSH_IF_REMOTE" ] ; then
rcp ${BINDIR}/config.guess $CLIENT:$TMP
else
cp ${BINDIR}/config.guess $TMP
fi
RSH_TO_CLIENT1=$?
REMOTE_OSnR=`$RSH_IF_REMOTE $CLIENT_IF_REMOTE $TMP/config.guess`
RSH_TO_CLIENT2=$?
export REMOTE_OSnR
#If either of these fail, this will be non-zero
RSH_TO_CLIENT=`expr $RSH_TO_CLIENT1 + $RSH_TO_CLIENT2`
#This section is designed to see if this client can rsh back to this
#Host. If it cannot, then it cannot be backed up
#Also, this is a good time to rsh over and touch the dumpdates file
#This is because many versions of dump will not create this file if it
#isn't already there.
. ${BINDIR}/rempath.sh
case $REMOTE_OSnR in
*aix* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
*bsdi* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
*dgux* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
*freebsd* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
*hpux9* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
*hpux10* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /var/adm/dumpdates ;;
*irix* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
*sysv4* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
*next* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
*osf* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates
$RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/vdumpdates ;;
*sco* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/ddates ;;
*sunos* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
*solaris* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
*ultrix* ) $RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_TOUCH /etc/dumpdates ;;
esac
#Remove the file if it is there, then tell the client to create it
rm -f $TMP/$X.$CLIENT.touchfile 2>/dev/null
if [ $SERVER = $CLIENT ] ; then
touch $TMP/$X.$CLIENT.touchfile
else
$L_RSH $CLIENT "$R_RSH $SERVER $L_TOUCH $TMP/$X.$CLIENT.touchfile"
fi
#If it's there, then the rsh worked, if not, it failed
[ -f $TMP/$X.$CLIENT.touchfile ] && RSH_FROM_CLIENT=0 || RSH_FROM_CLIENT=1
case $REMOTE_OSnR in
*aix* )
FSTAB=/etc/filesystems
;;
*bsdi*|*dgux*|*freebsd*|*next*|*osf*|*irix*|*ultrix*|*sunos*|*convex*|*linux*)
FSTAB=/etc/fstab
;;
*hpux9* )
FSTAB=/etc/checklist
;;
*hpux10* )
FSTAB=/etc/fstab
;;
*sysv4*)
FSTAB=/etc/vfstab
;;
*sco* )
FSTAB=/etc/default/filesys
;;
*solaris* )
FSTAB=/etc/vfstab
;;
esac
export FSTAB
if [ $RSH_TO_CLIENT -eq 0 -a $RSH_FROM_CLIENT -eq 0 ] ; then
if [ -z "$FILE_SYS" ] ; then
#Then this is supposed to be a full system backup
#So parse the "fstab" file for a list of all filesystems
INCLUDE_EXCLUDE_SH=$X.FSTAB.exclude.include.sh
echo "#!/bin/sh" > $TMP/$INCLUDE_EXCLUDE_SH
Log_err $? "Could not create $TMP/$INCLUDE_EXCLUDE_SH" exit
echo "[ -f $FSTAB.\$1 ] && $R_LS $FSTAB.\$1" >> $TMP/$INCLUDE_EXCLUDE_SH
Log_err $? "Could not create $TMP/$INCLUDE_EXCLUDE_SH" exit
chmod 755 $TMP/$INCLUDE_EXCLUDE_SH
Log_err $? "Could not chmod $TMP/$INCLUDE_EXCLUDE_SH" exit
if [ $SERVER != $CLIENT ] ; then
rcp $TMP/$INCLUDE_EXCLUDE_SH $CLIENT:$TMP
fi
INCLUDE_ONLY=`$RSH_IF_REMOTE $CLIENT_IF_REMOTE $TMP/$INCLUDE_EXCLUDE_SH \
only`
if [ -z "$INCLUDE_ONLY" ] ; then
#If there is an "$VFSTAB.only" file, that means to back up only the
#file systems listed in it. If there is NO such file, go ahead and
#parse the fstab file.
case $REMOTE_OSnR in
*aix* )
#This awk line is required to turn the multi-line, stanza format
#of aix's /etc/filesystems into a single-line variable
$RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_CAT $FSTAB |grep -v '^\*' \
|awk '$0 ~ /^\/.*:/ { printf $0 } $0 ~ /vfs.*=/ { print $0 }' \
|sed 's/ //g' \
|sed 's/[ ][ ]*vfs[ ][ ]*=[ ][ ]*//' \
|grep "^/" |egrep -v ':cdrfs|:nfs|/tmp:' >$TMPDF
;;
*bsdi*|*dgux*|*freebsd*|*next*|*osf*|*irix*|*ultrix*|*sunos*|*convex*|*linux*)
$RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_CAT $FSTAB | egrep -v '^#|:' \
| egrep "^/|#.*advfs" |grep -v '#.*#.*advfs' |awk '{ print $2":"$3 }' \
| egrep -v ':swap|:nfs|
roc|:iso9660|:nucfs|:dos|:cd*fs' \
| egrep -v ':rfs|:tmp|:hsfs|:swapfs|:ignore|
rocf*s*' \
| egrep -v '
cfs|:dos|:msdos|/tmp:|^\(.*\):' >$TMPDF
;;
*hpux9* )
$RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_CAT $FSTAB | egrep -v '^#|:' \
| grep "^/" |awk '{ print $2":"$3 }' \
| egrep -v ':swapf*s*|:nfs|
roc|:cdfs|:ignore' \
| egrep -v '/tmp:|^\(.*\):' >$TMPDF
;;
*hpux10* )
$RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_CAT $FSTAB | egrep -v '^#|:' \
| grep "^/" |awk '{ print $2":"$3 }' \
| egrep -vi ':swapf*s*|:nfs|:ignore|:cdfs|:nfs' \
| egrep -v '/tmp:|^\(.*\):' \
>$TMPDF
;;
*sysv4*)
$RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_CAT $FSTAB | egrep -v '^#|:' \
| grep "^/" | awk '{ print $3":"$4 }' \
| egrep -v ':swap|:nfs|
rocf*s*' \
| egrep -v '/tmp:|/dev/fd:|/dev/dsk/f' >$TMPDF
;;
*sco* )
#This awk line is required because sco's fstab can go over multiple lines
#each ending with a '\' until the last line. This turns them into
#one line, then chops out the extraneous data
$RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_CAT $FSTAB |egrep -v '^#|:' \
|awk '$NF ~ /\\/ { printf $0 } $NF !~ /\\/ { print $0 }' \
|sed 's/.*mountdir=//'|sed 's/[ ].*fstyp=/:/' \
|sed 's/[ ].*//'egrep -vi ':HS|
OS' >$TMPDF
;;
*solaris* )
$RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_CAT $FSTAB | egrep -vi ':|^#' \
|grep '^/' |awk '{ print $3":"$4 }' \
|egrep -v ':swap|:nfs|:hsfs|
roc|-:|/tmp:|/dev/fd:' >$TMPDF
;;
*)
#have to touch the file, or the rest would barf
touch $TMPDF
Log_err 1 "WARNING, $CLIENT_OS NOT supported, $HOST will not be backed up!"
;;
esac
else
echo '*****************************************************'|tee -a $LOG
echo "WARNING! This client has a $FSTAB.only file!" |tee -a $LOG
echo "ONLY file systems specified in that file will be backed up!" \
|tee -a $LOG
echo '*****************************************************'|tee -a $LOG
#have to touch the file, or the rest would barf
touch $TMPDF
fi
#Include and Exclude Section
#Checks to see if there are any extra file systems to be included, or
#If there are any ones that should be excluded
EXCLUDEFILE=`$RSH_IF_REMOTE $CLIENT_IF_REMOTE $TMP/$INCLUDE_EXCLUDE_SH \
exclude`
INCLUDEFILE=`$RSH_IF_REMOTE $CLIENT_IF_REMOTE $TMP/$INCLUDE_EXCLUDE_SH \
include`
[ $SERVER != $CLIENT ] && $L_RSH $CLIENT $R_RM -f $TMP/$INCLUDE_EXCLUDE_SH
for LINE in `cat $TMPDF` #For each file system that was in the "fstab"
do
FILE_SYS=`echo $LINE|awk -F: '{print $1}'`
#If there is an exclude file on the client, check to see if this
#File system is in it
if [ -n "$EXCLUDEFILE" ] ; then
EXCLUDE=`$RSH_IF_REMOTE $CLIENT_IF_REMOTE $R_CAT $FSTAB.exclude \
| grep "^${FILE_SYS}$"`
else
EXCLUDE=''
fi
#If it's not in the exclude file, then back it up, if so, then skip it
if [ -z "$EXCLUDE" ] ; then
echo $N "Including \"$CLIENT:$FILE_SYS:$REMOTE_OSnR\" $C" \
|tee -a $LOG
echo "in backup include list." |tee -a $LOG
echo $CLIENT:$LINE:$REMOTE_OSnR >> $TMPLIST
else
echo "Excluding \"$CLIENT:$FILE_SYS\" from backup include list." \
|tee -a $LOG
echo " (\"$FILE_SYS\" is in $CLIENT:$FSTAB.exclude.)" |tee -a $LOG
fi
done