03-31-2008
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
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Good Morning :)
I have a new challenge to solve, I am going to write a new backup disk mirroring script. The current one, whcih is useing 'dd' caused some stalled systems :(
Currently I am in the phase of experimenting with different methods, I was thinking about dump/restore afio/cpio or... (3 Replies)
Discussion started by: malcom
3 Replies
2. Solaris
I am running Solaris 10 and i need to mirror a 73 gig HD. How do you mirror one in Solaris? (2 Replies)
Discussion started by: dewsdwarfs
2 Replies
3. SCO
How Can I Do Mirroring In Unix? (0 Replies)
Discussion started by: DIMITRIOSDOUMOS
0 Replies
4. Solaris
Hi ,
I am trying to configure a private LAN and corporate LAN on the same machien on Solaris 10.
How can I achieve this?
Thanks (1 Reply)
Discussion started by: deedee
1 Replies
5. Solaris
Hello,
i'm pretty new in using solaris (5.10) and i'm kind of stuck with one problem. I'm trying to create a disk mirror cause of data redundancy. I've installed second disk in my system, prepared everything for creating a mirror (by following the instructions) and don't get any responce for... (7 Replies)
Discussion started by: n00b
7 Replies
6. UNIX for Advanced & Expert Users
LFTP Mirroring
We are planning to use lftp to mirror some of the files and
directories on to the remote server.
What we exactly want to do is mirror some of the directories and
exclude some of the the directories from "/" i.e. main root. . What
lftp is doing is... (0 Replies)
Discussion started by: sameerarora
0 Replies
7. Solaris
Hi All
i wish to mirror the root disk, but i face the below error.
root@saturn # metainit d11 1 1 c0t0d0s0
metainit: saturn: c0t0d0s0: is mounted on /
kindly assist... (27 Replies)
Discussion started by: SmartAntz
27 Replies
8. IP Networking
Hi,
We have a website running on a local centos 5.4 surfer, static IP.
The domain.com uses no-ip.com to take care of the DNS, it forwards all to my server.
My router receives the port 80 call, routes it to my server and the world can see domain.com perfectly fine.
However, we cannot see... (3 Replies)
Discussion started by: lawstudent
3 Replies
9. Red Hat
I am facing strange problem regarding hostname on my Linux(2.6.18-164.el5xen x86_64 GNU/Linux), the hostname changes if reboot with lan cable and with NO lan cable
Reboot with lan cable:
The hostname is ubunut
Unable to connect Oracle database using sqlplus some times database is not... (2 Replies)
Discussion started by: LinuxLearner
2 Replies
10. Solaris
Hi All
Please can I have some help/advice.
I am fairly new to unix so any help will be useful.
I need to perform HDD Mirroring on a Sun Fire V245 Server running Solaris 10 OS.
The system is already up and running and has the partitions and slices already.
Is it possible to perform the... (6 Replies)
Discussion started by: pluto.flame
6 Replies