Thanks kencunningham.
sys_backup looks like this.. you want me to test like this..
sys_backup script:--
#!/bin/ksh
#
# Name: sys_backup
# Purpose: This script makes a backup copy of filesystems that has a
# corresponding "b" filesystem. For example, the root (/) filesystem
# will be backup if there is a /backup_root filesystem mounted. The /usr
# filesystem will be backup if a /backup_usr is existing. And so on ...
# This script also prepares the alternate root file system
# for use as a bootable file system in the event that the real root (/)
# crashes.
# Assumptions:
# The alternate file systems are normally mounted in a read-only state.
# This shell needs to remount them read/write, and after we're done,
# restore them to read-only state. (We do this so no one can mistake
# "unmounted" slices as spares to be used for whatever.) So .. we assume
# that fstab has desired mount specs/options specified, so we don't use
# device names in mount cmds
# Revision History:
# 01/03/2000 -
# * checks for existence of "b" filesystems, quits if is existing
# * only backups filesystems with corresponding "b" filesystem.
# * sys_backup now uses newfs to clean the "b" fs
# * ufsdump now uses the raw device as input
# * won't quit if DiskSuite is not installed
# * comments out swap not on backup disk
# * eliminated all SunOS 4.x commands
#
#
#
##################################START OF FUNCTIONS##########################
#
ls <path>/normal_shutdown.flag 2>&1 /dev/null
if [ $? != 0 ]
then
exit
else
trap_handler()
{
# mounts the /b fs read only
CTR=1
/usr/sbin/sync
while [ $CTR -le $NUMFS ]
do
echo \"remounting ${BFS[$CTR]} ro\"
remount ${BFS[$CTR]} ro
CTR=$((CTR+1))
done
echo "sys_backup ended at `date +"%Y%m%d%H%M%S"`" | /usr/bin/tee -a $LOGFILE
}
baderror()
{
# put message out on stderr and mail to admin if warranted
if /usr/bin/tty -s
then
echo "$1"
else
echo $1 | /usr/bin/tee -a $LOGFILE
echo $1 | $MAILER -s "sys_backup error on $HOSTNAME" $ERRORSTO
fi
}
remount()
{
# unmount, remount file system $1 with desired $2 ro/rw option
/usr/sbin/umount $1 >> $LOGFILE 2>&1
if [ $? -ne 0 ]
then
baderror "failed to unmount $1"
exit 1
fi
/usr/bin/sleep 2
/usr/sbin/mount -o ${2:?} $1 >> $LOGFILE 2>&1
if [ $? -ne 0 ]
then
baderror "failed to remount $1 with $2 option"
exit 1
fi
/usr/bin/sleep 2
/usr/sbin/mount | /usr/bin/grep "^$1" > /dev/null 2>&1
if [ $? -ne 0 ]
then
baderror "failed to remount $1 with $2 option"
exit 1
fi
}
cleanup()
{
# remove old data in backup filesystem specified in $1
/usr/sbin/umount $1 >> $LOGFILE 2>&1
if [ $? -ne 0 ]
then
baderror "failed to unmount $1"
exit 1
fi
/usr/bin/sleep 2
echo y | /usr/sbin/newfs -m 1 $2 >> $LOGFILE 2>&1
if [ $? -ne 0 ]
then
baderror "failed during newfs of $2"
exit 1
fi
/usr/bin/sleep 2
/usr/sbin/mount -o rw $1 >> $LOGFILE 2>&1
if [ $? -ne 0 ]
then
baderror "failed to mount $1 with rw option"
exit 1
fi
/usr/bin/sleep 2
/usr/sbin/mount | /usr/bin/grep "^$1" > /dev/null 2>&1
if [ $? -ne 0 ]
then
baderror "$1 not mounted after newfs"
exit 1
fi
}
dodump()
{
# Check again if backup filesystem is mounted
/usr/sbin/mount | /usr/bin/grep "^$4" > /dev/null 2>&1
if [ $? -ne 0 ]
then
baderror "$4 not mounted before ufsdump/ufsrestore"
exit 1
fi
# dump device $3 (filesystem $1, device $2) to $4 (device $5)
/usr/sbin/ufsdump 0f - ${3:?} | (cd ${4:?}; /usr/sbin/ufsrestore ryf - ) >> $LOGFILE 2>&1
if [ $? -ne 0 ]
then
baderror "failed to dump $1 to $4"
exit 1
fi
echo "`date`: filesystem $1 on device $2 was dumped to filesystem $4 on device $5" | /usr/bin/tee -a $1/README-DUMPDATE | /usr/bin/tee -a $4/README-DUMPDATE | /usr/bin/tee -a $LOGFILE
}
editfstab()
{
# edit the backup vfstab (or equiv) to be sure the backup fs's
# are the one's that are mounted as real /
# real filesystem $1, device $2, raw device $3
# backup filesystem $4, block device $5, raw device $6
OLDREAL=`/usr/bin/grep "^$2[ | ]" $BFSTAB`
/usr/bin/cp -p $BFSTAB $BFSTAB.$DATE.sys_backup
/usr/bin/sed -e "\\%$1[ | ]%{
s%$2%$5%
s%$3%$6%
i\###bkup###$OLDREAL
a\###bkup###ABOVE ENTRIES CHANGED TO ALTER THE PRIMARY DEVICE (USING BKUP)
}
\\%$4[ | ]%{
s%^%###bkup### %
a\###bkup###ABOVE ENTRY WAS DISABLED - THIS IS NOW THE PRIMARY DEVICE
}" $BFSTAB.$DATE.sys_backup > $BFSTAB
}
##################################END OF FUNCTIONS##########################
##################################SHELL STARTS HERE#########################
#
# initialize variables
#
unset FS FSDEV FSRDEV BFS BFSDEV BFSRDEV
DATE=`date +"%Y%m%d%H%M%S"`
LOGFILE=/var/tmp/sys_backup.$DATE.log
FSTAB=/etc/vfstab
BROOT=/backup_root
BFSTAB=$BROOT/etc/vfstab
BSYSTEM=$BROOT/etc/system
MAILER=/usr/bin/mailx
#
# check for sys_backup alias in /etc/aliases and NIS if existing
# if not, send error messages to root on machine
#
if /usr/bin/grep "^sys_backup:" /etc/aliases > /dev/null 2>&1
then
ERRORSTO=`/usr/bin/grep "^sys_backup:" /etc/aliases | /usr/bin/cut -d\: -f2-`
elif /usr/bin/ypwhich > /dev/null 2>&1
then
if /usr/bin/ypcat -k aliases | /usr/bin/grep "^sys_backup" > /dev/null 2>&1
then
ERRORSTO=`ypcat -k aliases | /usr/bin/grep "^sys_backup" | /usr/bin/cut -d" " -f2-`
else
ERRORSTO="root"
fi
else
ERRORSTO="root"
fi
#
# Check if user running the script is root
#
if [ `/usr/ucb/whoami` != root ]
then
baderror "This script must be run as root."
exit 1
fi
echo "\nStarting sys_backup: $DATE" | /usr/bin/tee -a $LOGFILE
echo "-----------------------------------" | /usr/bin/tee -a $LOGFILE
echo "errors will be mailed to $ERRORSTO" | /usr/bin/tee -a $LOGFILE
case `/usr/bin/uname -s` in
SunOS) case `/usr/bin/uname -r` in
5.4) HOSTNAME=`/usr/ucb/hostname`
BOOTBLK=/usr/lib/fs/ufs/bootblk
;;
5.5.1|5.6|5.7|5.8) HOSTNAME=`/usr/bin/hostname`
BOOTBLK=/usr/platform/`/usr/bin/uname -i`/lib/fs/ufs/bootblk
;;
*) baderror "SunOS `/usr/bin/uname -r` no longer supported"
exit 1
;;
esac
;;
*) baderror "`/usr/bin/uname -s` platform not supported at the moment"
exit 1
;;
esac
#
# check if there is /backup_root fs on the system,
# if missing, no use continuing, get out now!
# if existing, store in as the first entry in the arrays
#
/usr/sbin/mount $BROOT > /dev/null 2>&1
if [ $? -eq 1 ]
then
baderror "there is no $BROOT filesystem"
exit 1
else
FS[1]=/
FSDEV[1]=`/usr/sbin/mount | /usr/bin/grep "^${FS[1]} " | /usr/bin/awk '{print $3}'`
FSRDEV[1]=`echo ${FSDEV[1]} | /usr/bin/sed -e 's/dsk/rdsk/g'`
BFS[1]=$BROOT
BFSDEV[1]=`/usr/sbin/mount | /usr/bin/grep "^$BROOT " | /usr/bin/awk '{print $3}'`
BFSRDEV[1]=`echo ${BFSDEV[1]} | /usr/bin/sed -e 's/dsk/rdsk/g'`
echo "storing ${FS[1]} and ${BFS[1]} in the arrays" | /usr/bin/tee -a $LOGFILE
fi
#
# store the other /backup_ fs in the arrays
#
CTR=2
for i in `/usr/sbin/mount | /usr/bin/grep "^/backup_" | /usr/bin/awk '{print $1}'`
do
if [ $i != "$BROOT" ]
then
/usr/sbin/mount `echo $i | /usr/bin/sed -e 's/\/backup_/\//g'` > /dev/null 2>&1
if [ $? -ne 1 ]
then
FS[$CTR]=`echo $i | /usr/bin/sed -e 's/\/backup_/\//g'`
FSDEV[$CTR]=`/usr/sbin/mount | /usr/bin/grep "^${FS[$CTR]} " | /usr/bin/awk '{print $3}'`
FSRDEV[$CTR]=`echo ${FSDEV[$CTR]} | /usr/bin/sed -e 's/dsk/rdsk/g'`
BFS[$CTR]=$i
BFSDEV[$CTR]=`/usr/sbin/mount | /usr/bin/grep "^$i " | /usr/bin/awk '{print $3}'`
BFSRDEV[$CTR]=`echo ${BFSDEV[$CTR]} | /usr/bin/sed -e 's/dsk/rdsk/g'`
echo "storing ${FS[$CTR]} and ${BFS[$CTR]} in the arrays" | /usr/bin/tee -a $LOGFILE
CTR=$((CTR+1))
else
baderror "$i is not a backup filesystem. skipping ..."
fi
fi
done
#
# get the size of the arrays
#
NUMFS=`echo ${#FS[*]}`
#
# compare size of array with counter
#
if [ $NUMFS -ne $((CTR-1)) ]
then
baderror "size mismatch between arrays and counter"
exit 1
fi
#
# OK - next we assume the file systems were mounted readonly, and we will now
# attempt to unmount/remount them rw. we then retest that each is mounted
# before moving on
#
CTR=1
while [ $CTR -le $NUMFS ]
do
echo "remounting ${BFS[$CTR]} rw" | /usr/bin/tee -a $LOGFILE
if remount ${BFS[$CTR]} rw
then
echo "${BFS[$CTR]} successfully remounted rw" | /usr/bin/tee -a $LOGFILE
else
baderror "failed to remount ${BFS[$CTR]} with rw option"
exit 1
fi
CTR=$((CTR+1))
done
#
# from this point on, we need to set a trap to remount the file systems r/o
# if possible
#
trap trap_handler 0 1 15
#
# OK - time to clean up the old data in the backup filesystems
# and then do the dumps
#
CTR=1
while [ $CTR -le $NUMFS ]
do
echo "cleaning up ${BFS[$CTR]}" | /usr/bin/tee -a $LOGFILE
if cleanup ${BFS[$CTR]} ${BFSRDEV[$CTR]}
then
echo "${BFS[$CTR]} successfully cleaned" | /usr/bin/tee -a $LOGFILE
else
baderror "failed to clean ${BFS[$CTR]}"
exit 1
fi
/usr/bin/sleep 2
echo "copying ${FS[$CTR]} to ${BFS[$CTR]}" | /usr/bin/tee -a $LOGFILE
if dodump ${FS[$CTR]} ${FSDEV[$CTR]} ${FSRDEV[$CTR]} ${BFS[$CTR]} ${BFSDEV[$CTR]}
then
echo "${FS[$CTR]} successfully copied to ${BFS[$CTR]}" | /usr/bin/tee -a $LOGFILE
else
baderror "failed to copy ${FS[$CTR]} to ${BFS[$CTR]}"
exit 1
fi
CTR=$((CTR+1))
done
#
# OK - need to install the boot block on the backup
#
RAWDEV=/dev/rdsk/`basename ${BFSRDEV[1]}`
echo "installing bootblock for raw device $RAWDEV" | /usr/bin/tee -a $LOGFILE
/usr/sbin/installboot $BOOTBLK $RAWDEV > /dev/null 2>&1
if [ $? -ne 0 ]
then
baderror "failed to install bootblock on $RAWDEV"
exit 1
fi
#
# OK - need to adjust vfstab (or equivalent) entries for / in the
# backup devices so they point to themselves
#
CTR=1
/usr/bin/cp -p $BFSTAB $BFSTAB.orig
echo "editing file $BFSTAB" | /usr/bin/tee -a $LOGFILE
while [ $CTR -le $NUMFS ]
do
echo "making ${BFS[$CTR]} the primary device" | /usr/bin/tee -a $LOGFILE
editfstab ${FS[$CTR]} ${FSDEV[$CTR]} ${FSRDEV[$CTR]} ${BFS[$CTR]} ${BFSDEV[$CTR]} ${BFSRDEV[$CTR]}
CTR=$((CTR+1))
done
#
# OK - need to edit system (kernel param) file so the meta device drivers
# are not loaded and Solstice DiskSuite is not started.
#
if /usr/bin/pkginfo -q SUNWmd
then
# edit the backup system (kernel param) file so that it ignores
# any meta device (Solstice DiskSuite) drivers
cp -p $BSYSTEM $BSYSTEM.orig
echo "editing file $BSYSTEM" | /usr/bin/tee -a $LOGFILE
/usr/bin/awk 'BEGIN {inMDDroot=0;inMDDdb=0}
/Begin MDD root info/{inMDDroot=1;print $0;break}
/End MDD root info/{inMDDroot=0; print $0;break}
/Begin MDD database info/{inMDDdb=1;print $0;break}
/End MDD database info/{inMDDdb=0; print $0;break}
{
if (inMDDroot == 1 || inMDDdb == 1)
print "*",$0
else
print $0
}' $BSYSTEM.orig > $BSYSTEM
if [ -f $BROOT/etc/rcS.d/S35SUNWmd.init ]
then
mv $BROOT/etc/rcS.d/S35SUNWmd.init $BROOT/etc/rcS.d/s35SUNWmd.init
fi
if [ -f $BROOT/etc/rc2.d/S95SUNWmd.sync ]
then
mv $BROOT/etc/rc2.d/S95SUNWmd.sync $BROOT/etc/rc2.d/s95SUNWmd.sync
fi
if [ -f $BROOT/etc/rc3.d/S25mdlogd ]
then
mv $BROOT/etc/rc3.d/S25mdlogd $BROOT/etc/rc3.d/s25mdlogd
fi
#
# comment out other filesystems using meta devices
# in /backup_root/etc/vfstab file
#
for i in `/usr/bin/grep "^/dev/md" $BFSTAB | /usr/bin/awk '{print $1}'`
do
METADEV=`/usr/bin/grep "^$i[ | ]" $BFSTAB`
/usr/bin/cp -p $BFSTAB $BFSTAB.$DATE.sys_backup
/usr/bin/sed -e "\\%$i[ | ]%{
s%^%###bkup### %
a\###bkup###ABOVE ENTRY WAS DISABLED - META DEVICES ARE NOT EXISTING
}" $BFSTAB.$DATE.sys_backup > $BFSTAB
done
fi
#
# comment out all swap devices not in the backup disk
#
BSWAPDEV=`/usr/bin/basename ${BFSDEV[1]} | /usr/bin/cut -c1-6`
for i in `/usr/bin/grep "[ | ]swap" $BFSTAB | /usr/bin/grep "^/dev" | /usr/bin/awk '{print $1}' | /usr/bin/grep -v $BSWAPDEV`
do
/usr/bin/cp -p $BFSTAB $BFSTAB.$DATE.sys_backup
/usr/bin/sed -e "\\%$i[ | ]%{
s%^%###bkup### %
a\###bkup###ABOVE ENTRY WAS DISABLED - SWAP NOT IN BACKUP DISK
}" $BFSTAB.$DATE.sys_backup > $BFSTAB
done
#
# create mini-copy of abars home in backup root unless already there
#
if /usr/bin/grep "^/abars" $FSTAB > /dev/null 2>&1
then
if [ ! -s $BROOT/abars/restit ]
then
# the following is used to create/update an emergency mini-home
# directory for abars to be used in the event of an emergency.
#
# ABARSHOME specifies current/old/permanent ABARS home dir
# MINIHOME specifies new/temp/backup ABARS home dir
#
ABARSHOME=~abars
MINIHOME=$BROOT/abars
FILELIST=".auth_code rc.abars abarsd restit .profile"
if [ ! -d $ABARSHOME ]
then
baderror "Can not find $ABARSHOME directory (permanent home of ABARS)"
exit 1
fi
[ -d $MINIHOME ] || mkdir $MINIHOME
if [ ! -d $MINIHOME ]
then
baderror "Can not find/create $MINIHOME directory to copy ~ABARS to"
exit 1
fi
/usr/bin/chown abars $MINIHOME
/usr/bin/chmod 0755 $MINIHOME
/usr/bin/cd $ABARSHOME
for file in $FILELIST
do
/usr/bin/cp -p $file $MINIHOME
/usr/bin/chown abars $MINIHOME/$file
done
echo "`date`: files copied from $ABARSHOME to $MINIHOME: $FILELIST" | tee -a $MINIHOME/README-BACKDATE
fi
fi
fi
rm <path>/normal_shutdown.flag
# End of script
I did add in shutdown script as you mention me to do ..and all rest of the stuff.