Saturday, March 2, 2013

Max DB Replication Scripts

Max DB Replication Configuration for Standby modules

Scripts for automating standby Max Db

Shipping of the redo log backups

Once the standby instances data area contains a complete data backup of the primary instance, the standby instance can be updated by recovering log backups of the primary instance.

This is only possible if all redo log backups that had been created after the initial data backup had been done are applied in the order the backups where created.

If any log is missing in the sequence no further logs can be applied to the standby instance.

We need to ship log backups from Primary Maxdb Server - prodmaxdb server to DR server - stdmaxdb to the location lc_backup.

Secondly we need to ensure that log files which are shipped should have permission 666 and owner of the files should be sdb:sdba and slpadm has the permission to delete the same after applying.

Script

At user home location save the scripts : restore.txt and restore_script.sh

It only restores 1 log backup on each run.

Restore.txt has the commands that the dbmcli should execute once inside the dbmcli.

Contents of restore.txt

db_admin

db_connect

recover_start LOG_BACKUP LOG 1060

db_admin

db_connect

recover_replace LOG_BACKUP /lc_backup/LOG_BACKUP_060110 1061

recover_cancel

The restore_script.sh has the logic for changing restore.txt before executing it.

#!/bin/bash

IND=`ls /lc_backup/LOG_BACKUP_060110* | cut -d. -f2 | sort -r | tail +2 | sort -r`

for i in $IND; do

ANT=`echo $i - 1 | bc`

POS=`echo $i + 1 | bc`

sed '/recover_start/s/'$ANT'/'$i'/g' /home/slpadm/restore.txt | sed '/recover_replace/s/'$i'/'$POS'/g' > /tmp/restore.$i.tmp

DIF=`diff /home/slpadm/restore.txt /tmp/restore.$i.tmp | wc -l`

if [[ $DIF == 0 ]] ; then

echo "Error"

else

cp /tmp/restore.$i.tmp /home/slpadm/restore.txt

chown sdb:sdba /lc_backup/*

chmod 666 /lc_backup/*

dbmcli -n [Primary Maxdb Server IP] -d SLP -u control,welcome -c -i /home/slpadm/restore.txt

if [[ $? == 0 ]] ; then

  rm /lc_backup/LOG_BACKUP_060110.$i

  rm /tmp/restore.$i.tmp

else

  echo "Error"

  exit 1

fi

fi

done

exit 0

  Monitoring

We can check whether log file is applied or not by checking the output of the script located at /home/slpadm – MaxdbRestore.log

recover_start LOG_BACKUP LOG 1060

    OK
    Returncode              -8020
    Date                    20100820
    Time                    00100652
    Server                  prodmaxdb
    Database                SLP
    Kernel Version          Kernel    7.6.04   Build 009-123-182-193
    Pages Transferred       42688
    Pages Left              0
    Volumes                 1
    Medianame               LOG_BACKUP
    Location                /lc_backup/LOG_BACKUP_060110.1060
    Errortext              
    Label                   LOG_000001060
    Is Consistent         
    First LOG Page          43679963
    Last LOG Page           43722628
    DB Stamp 1 Date         20100814
    DB Stamp 1 Time         00095734
    DB Stamp 2 Date         20100816
    DB Stamp 2 Time         00010840
    Page Count              42666
    Devices Used            1
    Database ID             prodmaxdb:DBID
    Max Used Data Page    
    Converter Page Count  

Also you can check the status of the database in Windows – Database Manager.

No comments: