ITPub博客

首页 > 数据库 > Oracle > GoldenGate 自动化初始数据

GoldenGate 自动化初始数据

原创 Oracle 作者:gycixput 时间:2018-09-05 13:22:13 0 删除 编辑

  针对于上次《GoldenGate 自动化初始数据》过程中,存在的不适合场景,调整脚本,并对脚本进行优化,源端包括ogg_expdp.sh,目标端包括stop_rep.sh和ogg_impdp.sh

 ogg_expdp.sh首先检查ogg抽取进程是否正常,正常则导出数据,否则重置抽取时间,启动抽取进程。

 stop_rep.sh停止rep进程。

 ogg_impdp.sh首先检查rep进程是否运行,运行则退出执行提示先执行stop_rep.sh,未运行则导入数据后启动复制。

stop_rep.sh脚本内容如下:

#!/bin/bash


ggsci=/ogghome/goldengate/ggsci


echo 'kill rep_rep_cs' | $ggsci


if [ $? -ne 0 ]; then

   echo "Stop rep_rep_cs is failed, Please use ggsci check rep_rep_cs status"

else

   echo "Rep_rep_cs has been stop!!! "

fi


ogg_impdp.sh脚本内容如下:

#!/bin/bash


##used for impdp

connect=gaoyc/gaoyc_123

prefile=ogg_gaoyc

diry=expdp_dir

dmp_dir=/orabak/expdp

ggsci=/ogghome/goldengate/ggsci

ogg_dir=/ogghome/goldengate




##check rep_rep_cs status


echo "First check rep_rep_cs is running......"

rep_stats=`echo 'status rep_rep_cs' | $ggsci | grep REP_TZDB | awk -F ':' {'print $2'} |grep -o "[^ ]\+\+[]\+\+[]\+*"`

echo "rep_rep_cs status is : $rep_stats"





function exit_script()

{

    exit 1

}


if [ "$rep_stats" == "RUNNING" ]; then

      echo "rep_rep_cs is running, Please stop rep_rep_cs, then expdp "

      echo "Please execute stop_ogg.sh,ogg_expdp.sh first"

      exit_script

else

        echo "rep_status was stoped, continue"

fi


echo "Drop tables "


sqlplus -s / as sysdba<<EOF

truncate table gaoyc.t1;

truncate table gaoyc.t2;

......

truncate table gaoyc.ogg_test;

exit

EOF


if [ $? -eq 0 ]; then

   echo "tables has been droped"

else

   echo "exit scripts, please check error"

   exit_script

fi



echo "Begin import talbes"


cd $dmp_dir

csn=`cat $prefile.log | grep  -i flashback_s | awk -F '=' {'print $5'} | awk {'print $1'}`


echo "scn: $csn"


impdp $connect directory=$diry dumpfile=$prefile.dmp logfile=$prefile_imp.log INCLUDE=TABLE_DATA


if [ $? -eq 0 ]; then

          echo "tables has been imported"

        else

          echo "tables failed to import"

          exit_script

        fi


rm $prefile*


cd $ogg_dir

commd="start rep_rep_cs,  ATCSN $csn"

echo $commd


echo $commd | $ggsci

ogg_expdp.sh脚本内容如下:

#!/bin/bash


# Used for expdp and ftp

BACKUPDIRECTORY=/orabak/expdp

REMOTE_DIR=/orabak/expdp

connect=gaoyc/Gaoyc_123

prefile=ogg_gaoyc

diry=expdp_dir

ggsci=/ogghome/goldengate/ggsci


#used for check ext_cs and restart ext_cs

echo "First check ext_cs is running??"

ext_stats=`echo 'status ext_cs' | $ggsci | grep EXT_TZDB | awk -F ':' {'print $2'} |grep -o "[^ ]\+\+[]\+\+[]\+*"`


echo $ext_stats


function exit_script()

{

    exit 1

}


function change_ext_cs()

{

   echo "Begin Chhange ext_cs extract time"

   echo 'alter ext_cs, begin now' | $ggsci

   if [ $? -eq 0 ]; then

      echo "Ext_cs has been changed!!!!!!"

   else

      echo "Ext_cs has changed failed, please check info using ggsci"

      exit_script

   fi

   echo 'start ext_cs' | $ggsci

   if [ $? -eq 0 ]; then

      echo "Ext_cs has been started!!!!"

   else

      echo "Ext_Tzdb started failed, Please check info"

      exit_script

   fi


}


if [ "$ext_stats" == "RUNNING" ]; then

        echo 'kill ext_cs' | $ggsci

        if [ $? -eq 0 ]; then

          echo "Ext_cs has been stoped!!!!"

          change_ext_cs

        else

          echo "Ext_cs stop was failed!!!!!!"

          exit_script

        fi

        echo "Ext_staus is running !!!!"

else

        echo "Ext_status is not running!!!!"

        change_ext_cs

fi


###Used for used for expdp tables


echo "Begin expdp tables"


fcn=`sqlplus -S / as sysdba <<EOF 

select  'curnt_scn:'||dbms_flashback.get_system_change_number scn from dual;

 exit

 EOF`


fsn=`echo $fcn | awk -F ':' {'print $2'}`

echo "SCN: $fsn"


expdp $connect directory=$diry dumpfile=$prefile.dmp logfile=$prefile.log flashback_scn=$fsn tables=t1,t2,ogg_test


echo "Expdp has been Successfull!!!"

ftp -n<<EOF

open 192.168.1.61

user oracle oracle

cd $REMOTE_DIR

lcd $BACKUPDIRECTORY

prompt off

bin

mput $prefile*

bye

EOF


echo "Dump is send to   192.168.1.61 "

cd $BACKUPDIRECTORY

rm $prefile*

echo "Dump is deleted"


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24585765/viewspace-2213591/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-11-05

  • 博文量
    57
  • 访问量
    182562