GoldenGate 自動化初始資料

gycixput發表於2018-08-06

源端、目標端環境如下:

SLES 11SP4

Oracle 11.2.0.4

GoldenGate: 11.2.1.0.33


涉及使用者相關資訊中資料表及密碼已加密或替換。

指令碼說明:

 複製出現問題或其他原因需要做ogg初始化需在源端執行ogg_expdp.sh,執行完成後,需要在目標端執行ogg_impdp.sh,執行完成後複製關係啟動。

源端ogg_expdp.sh內容:

racle@test2:/orabak> more ogg_expdp.sh 

#!/bin/bash


BACKUPDIRECTORY=/dbbackup

REMOTE_DIR=/dbbackup

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 Gaoyc/XXXCCC  dumpfile=ogg_Gaoyc.dmp logfile=ogg_Gaoyc.log directory=expdp_dir  flashback_scn=$fsn tables=table1,table2,table3


ftp -n<<EOF

open 192.168.15.210

user oracle gyc123

cd $REMOTE_DIR

lcd $BACKUPDIRECTORY

prompt off

bin

mput ogg_Gaoyc*

bye

EOF


echo "Dump is send to 192.168.15.210"

cd $BACKUPDIRECTORY

rm ogg_Gaoyc*

echo "Dump is deleted"



目標端ogg_impdp.sh內容:

[oracle@testdb orabak]$ more ogg_impdp.sh 

#!/bin/bash


dmp_dir=/dbbackup

ogg_dir=/goldengate

q_name=rep_tzdb



sqlplus -s / as sysdba<<EOF

truncate table  Gaoyc.table1;

truncate table  Gaoyc.table2;

truncate table  Gaoyc.table3;


exit

EOF



cd $dmp_dir

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


echo "scn: $csn"


impdp Gaoyc/gyc01  dumpfile=ogg_Gaoyc.dmp logfile=ogg_Gaoyc_impdp.log directory=expdp_dir INCLUDE=TABLE_DATA


echo "Import has been completed"

rm ogg_Gaoyc.*


cd $ogg_dir

commd="start rep_tzdb,  ATCSN $csn"

echo $commd


echo $commd | ./ggsci



說明:

  初始化涉及兩個指令碼,可以合併為一個指令碼,中間可透過ssh無密碼登入執行另一個指令碼或者透過expect遠端登入執行。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24585765/viewspace-2199242/,如需轉載,請註明出處,否則將追究法律責任。

相關文章