Masato Taruishi
taru****@users*****
2004年 10月 14日 (木) 11:12:25 JST
=================================================================== RCS file: ultrapossum/module/failover/recovery,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ultrapossum/module/failover/recovery 2004/10/13 11:00:07 1.10 +++ ultrapossum/module/failover/recovery 2004/10/14 02:12:25 1.11 @@ -27,80 +27,85 @@ exit 1 fi -RPLDIR=$NFSDIR/$RPLDIR +WORKDIR=$LOGDIR/recovery/`date +%Y%m%d%H%M%S` +install -d $WORKDIR/replica/ -TMPDIR=/tmp -TMPRPL=replica.$$ +SLURPDREPLOGFILE="$SLURPDRPLDIR/replica/slurpd.replog" +SLURPDSTATUSFILE="$SLURPDRPLDIR/replica/slurpd.status" -OWN=$HOST -OTHER=$ANOTHER_MASTER - -echo -n "Checking for recovery status... " 1>&2 - -# check for replication log of previous master server -needrecover=0 - -install -d $RPLDIR/$OWN $RPLDIR/$OTHER $RPLDIR/$OWN/replica $RPLDIR/$OTHER/replica - -if ! [ -f $RPLDIR/$OWN/replog ] && [ -f $RPLDIR/$OTHER/replog ]; then - $MODULEDIR/failover/checkreplog $RPLDIR/$OTHER/replog $RPLDIR/$OWN/replog || exit 1 - needrecover=1 - echo -n "n" 1>&2 -fi - -if [ $RPLDIR/$OTHER/replog -nt $RPLDIR/$OWN/replog ]; then - $MODULEDIR/failover/checkreplog $RPLDIR/$OTHER/replog $RPLDIR/$OWN/replog || exit 1 - needrecover=1 - echo -n "o" 1>&2 -fi - -if ! [ -f $RPLDIR/$OWN/replica/slurpd.replog ] && [ -f $RPLDIR/$OTHER/replica/slurpd.replog ]; then - $MODULEDIR/failover/checkreplog $RPLDIR/$OTHER/replica/slurpd.replog $RPLDIR/$OWN/replica/slurpd.replog || exit 1 - needrecover=1 - echo -n "N" 1>&2 -fi - -if [ $RPLDIR/$OTHER/replica/slurpd.replog -nt $RPLDIR/$OWN/replica/slurpd.replog ]; then - $MODULEDIR/failover/checkreplog $RPLDIR/$OTHER/replica/slurpd.replog $RPLDIR/$OWN/replica/slurpd.replog || exit 1 - needrecover=1 - echo -n "O" 1>&2 -fi - -if [ $RPLDIR/$OTHER/replica/slurpd.status -nt $RPLDIR/$OWN/replica/slurpd.status ]; then - echo -n "s" 1>&2 - if $MODULEDIR/failover/checkstatus -f $ULTRAPOSSUM_MASTER_SLAPD_CONF $RPLDIR/$OTHER/replica/slurpd.status - then - cp $RPLDIR/$OTHER/replica/slurpd.status $RPLDIR/$OWN/replica/slurpd.status || exit 1 - elif [ $? -eq 1 ]; then - cp $RPLDIR/backup/slurpd.status $RPLDIR/$OWN/replica/slurpd.status || exit 1 +ANOTHER_REPLOGFILE="$NFSDIR/$RPLDIR/$ANOTHER_MASTER/replog" +ANOTHER_SLURPDREPLOGFILE="$NFSDIR/$RPLDIR/$ANOTHER_MASTER/replica/slurpd.replog" +ANOTHER_SLURPDSTATUSFILE="$NFSDIR/$RPLDIR/$ANOTHER_MASTER/replica/slurpd.status" + +BACKUP_SLURPDSTATUSFILE="$NFSDIR/$RPLDIR/backup/slurpd.status" + +WORK_REPLOGFILE=$WORKDIR/replog +WORK_SLURPDREPLOGFILE=$WORKDIR/replica/slurpd.replog +WORK_SLURPDSTATUSFILE=$WORKDIR/replica/slurpd.status + +check_replog() { + + recover=0 + + echo -n "Checking for $ANOTHER_REPLOGFILE... " 1>&2 + if [ $ANOTHER_REPLOGFILE -nt $REPLOGFILE ]; then + $MODULEDIR/failover/checkreplog $ANOTHER_REPLOGFILE $WORK_REPLOGFILE + echo "newer than $REPLOGFILE" 1>&2 + recover=1 + else + /bin/cp $REPLOGFILE $WORK_REPLOGFILE + echo "up-to-date" 1>&2 + fi + + echo -n "Checking for $ANOTHER_SLURPDREPLOGFILE... " 1>&2 + if [ $ANOTHER_SLURPDREPLOGFILE -nt $SLURPDREPLOGFILE ]; then + $MODULEDIR/failover/checkreplog $ANOTHER_SLURPDREPLOGFILE $WORK_SLURPDREPLOGFILE + echo "newer than $SLURPDREPLOGFILE" 1>&2 + recover=1 + else + /bin/cp $SLURPDREPLOGFILE $WORK_SLURPDREPLOGFILE + echo "up-to-date" 1>&2 + fi + + echo -n "Checking for $ANOTHER_SLURPDSTATUSFILE... " 1>&2 + if [ $ANOTHER_SLURPDSTATUSFILE -nt $SLURPDSTATUSFILE ]; then + if $MODULEDIR/failover/checkstatus -f $ULTRAPOSSUM_MASTER_SLAPD_CONF $ANOTHER_SLURPDSTATUSFILE; then + /bin/cp $ANOTHER_SLURPDSTATUSFILE $WORK_SLURPDSTATUSFILE + echo "newer than $SLURPDSTATUSFILE" 1>&2 else - exit 1 + /bin/cp $BACKUP_STATUSFILE $WORK_SLURPDSTATUSFILE + echo "newer than $BACKUP_SLURPDSTATUSFILE" 1>&2 fi + recover=1 + else + /bin/cp $SLURPDSTATUSFILE $WORK_SLURPDSTATUSFILE + echo "up-to-date" 1>&2 + fi + + if test "x$recover" != "x1"; then + echo "Recovery not required" 1>&2 + /bin/rm -rf $WORKDIR + fi + +} + +check_replog +if test -d "$WORKDIR"; then + if test "`$MODULEDIR/server/startup status`" = "stopped"; then + $MODULEDIR/server/startup slave_start + fi + cat $WORK_REPLOGFILE >> $WORK_SLURPDREPLOGFILE + echo -n "Recovery starting... " 1>&2 + $SHAREDIR/envexec $SLURPD -d $SLURPD_DEBUGLEVEL -o -f $CONFDIR/recovery.conf -r $WORK_SLURPDREPLOGFILE -t $WORKDIR > $WORKDIR/slurpd.log 2>&1 + echo "done" 1>&2 + grep request $WORKDIR/slurpd.log | grep done | tail -1 1>&2 + echo -n "Updating $HOST replogs... " 1>&2 + /bin/cp /dev/null $REPLOGFILE + /bin/cp $WORK_SLURPDREPLOGFILE $SLURPDREPLOGFILE + /bin/cp $ANOTHER_SLURPDSTATUSFILE $WORK_SLURPDSTATUSFILE + echo "done" 1>&2 + echo "Log: $WORKDIR" 1>&2 fi -echo " done" 1>&2 - - # import master data -if [ $needrecover -gt 0 ]; then - echo -n "Preparing recovery replication log... " 1>&2 - mkdir $TMPDIR/$TMPRPL - /bin/cp -r $RPLDIR/$OWN/replica $TMPDIR/$TMPRPL - echo -n "." 1>&2 - cat $RPLDIR/$OWN/replog >> $TMPDIR/$TMPRPL/replica/slurpd.replog - echo -n "." 1>&2 - if test "`$MODULEDIR/server/startup status`" = "stopped"; then - $MODULEDIR/server/startup slave_start - sleep 1 - fi - echo "done" 1>&2 - echo "Import master data" 1>&2 - echo "replica: $TMPRPL/replica" 1>&2 - echo "$SLURPD -d $SLURPD_DEBUGLEVEL -o -f $CONFDIR/recovery.conf -r $TMPDIR/$TMPRPL/replica/slurpd.replog -t $TMPDIR/$TMPRPL" 1>&2 - if ! $SHAREDIR/envexec $SLURPD -d $SLURPD_DEBUGLEVEL -o -f $CONFDIR/recovery.conf -r $TMPDIR/$TMPRPL/replica/slurpd.replog -t $TMPDIR/$TMPRPL 2>&1 > $TMPDIR/$TMPRPL/slurpd.log.$$; then - echo "Error: importing slurpd abnormally exitted" 1>&2 - cat $TMPDIR/$TMPRPL/slurpd.log.$$ 1>&2 - else - rm -rf $TMPDIR/$TMPRPL - fi -fi +exit 0