|
using cpio to sync machines
Here's an example script that uses cpio to sync machines. It is a little network heavy, but works great for snapshots on smaller partitions. Note host equivalency must be set up for the account this runs from.
"makes" 285 lines, 7809 characters
:
# Quentin Krengel Tue Jan 30 16:43:01 CST 1996
#GENDIST
ARG=$1
ARCHIVE=1
######################
#echo "
#This script can only be used on two SCO Unix machines running identical
#revisions of the same operating system. The script must be scrutinized
#and tailored to your architecture before exection."
#exit 0
######################
# The primary machine names, as defined below must be listed in the
# secondary machine's /.rhosts file, and permissions of the file must
# be set to 644.
# The secondary machine names, as defined below must be listed in the
# primary machine's /.rhosts file, and permissions of the file must
# be set to 644.
[ $# -eq 0 ] && {
echo "`basename $0`:must specify archive, update, start, or stop"
}
if [ $ARG = archive ]
then
else
SD=/etc/sentinel.d
ROLE=`cat $SD/role`
: ${ROLE:=NULL}
[ $ROLE = NULL ] && {
echo "Sentinel file $SD/role not defined, bye!"
exit 1
}
[ `cat $SD/roles | wc -l` -gt 2 ] && {
echo "Sentinel file $SD/roles has too many entries. bye!"
exit 1
}
MACHINE=`grep $ROLE /etc/sentinel.d/roles |cut -f1`
OTHER_MACHINE=`grep -v $ROLE /etc/sentinel.d/roles |cut -f1`
synctime() {
# sync secondary system clock to primary system for cpio
echo \
" \n**\tSyncing standby machine $OTHER_MACHINE clock to $MACHINE..."
date +%y%m%d%H%M |rcmd $OTHER_MACHINE /etc/asktime
}
# cpio transfer file name
CPIOF="/tmp/cpio$$"
# cpio install script name
CPIOI="/tmp/inst$$"
cpiover() {
# use cpio to preserve symbolic links
echo "\n----<<*- $1 -*>>----"
echo "**-Creating cpio transfer file $CPIOF for $1"
find $1 -print | cpio -Vo >$CPIOF
echo "**-Copying transfer file $CPIOF to $OTHER_MACHINE"
rcp $CPIOF ${OTHER_MACHINE}:${CPIOF}
echo "cat $CPIOF |cpio -id 2>/dev/null" >$CPIOI
echo "rm $CPIOF" >>$CPIOI
echo "rm $CPIOI" >>$CPIOI
chmod 700 $CPIOI
echo "**-Transferring $CPIOF to $OTHER_MACHINE"
rcp $CPIOI ${OTHER_MACHINE}:${CPIOI}
rm $CPIOI
echo "**-Installing $CPIOI onto $OTHER_MACHINE"
rcmd $OTHER_MACHINE $CPIOI
}
rcpover() {
echo "**-Copying $1 to $OTHER_MACHINE"
rcp $1 ${OTHER_MACHINE}:$1
}
## main starts here
case $ARG in
"update")
[ `logname = root ` ] || {
echo "$0: Must be run by root. Goodbye."
exit 1
}
[ $ROLE = primary ] || {
echo "$0: /etc/sentinel.d/role = `cat /etc/sentinel.d/role` "
echo "`basename $0` update: must be run on the primary machine."
echo "See $SD/role"
exit 1
}
synctime
cpiover /usr/local
rcpover /.profile
rcpover /.forward
rcpover /.dvsc
rcpover /etc/default/accounts
rcpover /etc/default/vsinet
rcpover /etc/default/vsifax
rcpover /etc/default/vsifax.vars
rcpover /etc/default/lpd
rcpover /etc/default/mega
rcpover /etc/default/mega.defs
rcpover /etc/default/authsh
rcpover /etc/default/passwd
rcpover /etc/dialups
## not for sentinel! rcpover /etc/defalt/filesys
rcpover /etc/exports
#echo "**-Requesting reread of exports on $OTHER_MACHINE"
#rcmd $OTHER_MACHINE "/etc/exportfs -a"
rcpover /etc/printcap
#note customzed PS1 promts
#rcpover /etc/profile
# handled by ap rcpover /etc/group
echo "Creating account profiles map"
ap -vdg > /tmp/ap.map
rcpover /tmp/ap.map
echo "Installing account profiles to $OTHER_MACHINE"
rcmd $OTHER_MACHINE "/tcb/bin/ap -rov -f/tmp/ap.map"
rcpover /usr/lib/uucp/Systems
rcpover /usr/lib/uucp/Permissions
rcpover /usr/lib/uucp/Devices
rcpover /usr/lib/uucp/Dialers
rcpover /usr/lib/mkuser/sh/profile
rcpover /usr/lib/mkuser/homepaths
rcpover /usr/lib/mkuser/lib/mkuser.lib
rcpover /usr/lib/mkuser/lib/mail
cpiover /var/spool/lp
#rcpover /var/spool/lp/remote
#cpiover /var/spool/lp/admins/lp/interfaces
#cpiover /var/spool/lp/model
#rcpover /var/spool/lp/.rhosts
rcpover /etc/hosts
rcpover /etc/hosts.equiv
rcpover /.rhosts
echo "\n----<<*- File Updates for DCI Unibasic -*>>----"
# DCI tech support says we can copy these files over verbatim if we are
# using a hardware key
cpiover /etc/DCI/*
cpiover /usr/ub/*
# we don't want all entries in /usr/spool/cron/crontabs/root
# we'll extract the entries in the "@SENTINAL area and store them on the
#secondary machine.
echo "\n----<<*- Update $OTHER_MACHINE with @SENTINAL crontabs -*>>----"
TMPF0=/tmp/crontab0.$$
TMPF1=/tmp/crontab1.$$
crontab -l > $TMPF0
SENTINAL=0
while read line
do
echo -n "."
if [ `echo "$line" |grep -s -e"#@SENTINAL" |wc -l` -gt 0 ]
then
#toggle sentinal switch. Save lines to temp file between markers.
if [ $SENTINAL = 0 ]
then
SENTINAL=1
else
SENTINAL=0
fi
fi
[ $SENTINAL = 1 ] && echo "$line" >> $TMPF1
done < $TMPF0
echo "."
cp $TMPF1 /usr/local/lib/crontab.standup
chmod 600 /usr/local/lib/crontab.standup
rcpover /usr/local/lib/crontab.standup
echo "\n----<<*- File Updates for Equinox devs -*>>----"
# From Buck at Equinox Tech Support
# When going into fallback mode, write the following files from
# the primary system to the secondary system.
cp /etc/inittab /etc/inittab.standup
echo \
"**-Storing /etc/inittab with equinox devs as /etc/inittab.standup"
rcpover /etc/inittab.standup
# if we're not in fallback mode, strip out equinox devices and tty04
rcmd $OTHER_MACHINE \
"/bin/sed -e '/^E/d' -e '/^c04/d' /etc/inittab.standup \
> /etc/inittab"
rcpover /etc/conf/init.d/mpdi
rcpover /etc/ttytype
rcpover /etc/default/mega
rcpover /etc/auth/system/devassign
## Star requires the following file updates
echo "\n----<<*- File Updates for Star Technologies -*>>----"
rcpover /etc/d_passwd
rcpover /etc/gettydefs
cpiover /tcb/files/auth
rcpover /etc/auth/system/authorize
cpiover /tcb/files/rootcmds
rcpover /usr/bin/ucopy
echo \
"\n\nPlease note, the following must be maintained on both machines."
echo "
/etc/hosts
/etc/rc*
"
;;
"start")
if [ $ROLE = standby ]
then
echo "executing $0 start..." > /dev/console
# most of this is handled in /etc/sentinel.d/S* but a few things are
# made easier here because we are running the same version and release
# of OS on both machiens. Handling inittab this way saves keeping two
# copies up to date.
cp /etc/inittab.start /etc/inittab
### handled by shutdown
# have to shut machine down and reboot to get Equinox boards reset
## /etc/sentinel.d/S* issues the command "megaopt all" to force a
# reset with Equinox
#/etc/megaopt all
## Issue the command init Q to force the kernel to reread inittab
#init Q
# share exported file systems now that they are mounted
#/etc/exportfs -a
# /etc/sentinel.d/S* stops and restarts offmgr, wpexc, wpexc51,
# and fx servers when changing modes
###
#crontab notes:
# we previosly stored crontab entries that need to run on this
# machine (search for "crontab" above).
crontab -l > /usr/local/lib/crontab.standown
crontab -l > /tmp/crontab.root
cat /usr/local/lib/crontab.standup >> /tmp/crontab.root
crontab /tmp/crontab.root
# change default printer
lpadmin -d mishp
#
else
echo "Skipping $0 start: Primary machine" > /dev/console
fi
;;
"stop")
if [ $ROLE = standby ]
then
echo "executing $0 stop..." > /dev/console
# most of this is handled in /etc/sentinel.d/K*
/bin/sed -e '/^E/d' -e '/^c04/d' /etc/inittab.standup \
> /etc/inittab
init Q
#change default printer
lpadmin -d smp
crontab /usr/local/lib/crontab.standown
else
echo "Skipping $0 start: Primary machine" > /dev/console
fi
;;
esac
|