Задача: раз в сутки обновлять snapshot standby базу до актуального состояния.
Делается это путем перевода в physycal standby и наката накопленных за день архивов. После завершения обновления база снова переключается в snapshot standby.
Для Windows:
@echo off
set ORACLE_SID=axtest
set ORACLE_HOME=G:\oracle\ora11204
set prim_db=prd
set std_db=std
set cred=sys/p@S$w0Rd
echo ####################################################################
echo Refresh started at %time%
echo .
echo ####################################################################
set role = PHYSICAL
%ORACLE_HOME%\bin\dgmgrl %cred%@%prim_db% "convert database %std_db% to %role% standby"
echo Now we are waiting for apply to finish. It'll take some time.
echo ...
:wait
ping 127.0.0.1 -n 30 >null
%ORACLE_HOME%\bin\dgmgrl %cred%@%prd% "show database %std%" > log\lag.tmp
for /f "tokens=3 delims= " %%i in ('find "Transport Lag" log\lag.tmp') do set tlag=%%i
if %tlag% neq 0 goto :wait
for /f "tokens=3 delims= " %%i in ('find "Apply Lag" log\lag.tmp') do set alag=%%i
if %alag% neq 0 goto :wait
echo Redo apply finished. Converting back to snapshot standby.
%ORACLE_HOME%\bin\dgmgrl %cred%@%prim_db% "convert database %std_db% to %role% standby"
echo ####################################################################
echo Refresh finished at %time%
echo .
echo ####################################################################
Для Linux:
# ENV part
ORACLE_SID=axtest
ORAENV_ASK=NO
. oraenv
export primary=axprd
export standby=axstd
export cred=sys/p@s$w0Rd
# Functions
function std_convert() {
mode=$1
dgmgrl $cred@$primary "convert database $standby to $mode standby"
}
function lag_check() {
alag=$(dgmgrl $cred@$primary "show database $standby" | grep "Apply Lag" | awk -F" " '{print $3}')
tlag=$(dgmgrl $cred@$primary "show database $standby" | grep "Transport Lag" | awk -F" " '{print $3}')
lag=$(($alag+$tlag))
echo $lag
}
{ echo Refresh started at; date; } | tr "\n" " "
# Actual refresh.
std_convert "physycal"
echo Waiting for apply to finish. This may take hours...
# что то тут не сработал выход из цикла (to be fixed)
while [ $(lag_check) -ge 0 ];do
lag_check
sleep 30
done
dgmgrl $cred@$primary "show database $standby" | grep "Lag"
std_convert "snapshot"
{ echo Refresh finished at; date; } | tr "\n" " "
Делается это путем перевода в physycal standby и наката накопленных за день архивов. После завершения обновления база снова переключается в snapshot standby.
Для Windows:
@echo off
set ORACLE_SID=axtest
set ORACLE_HOME=G:\oracle\ora11204
set prim_db=prd
set std_db=std
set cred=sys/p@S$w0Rd
echo ####################################################################
echo Refresh started at %time%
echo .
echo ####################################################################
set role = PHYSICAL
%ORACLE_HOME%\bin\dgmgrl %cred%@%prim_db% "convert database %std_db% to %role% standby"
echo Now we are waiting for apply to finish. It'll take some time.
echo ...
:wait
ping 127.0.0.1 -n 30 >null
%ORACLE_HOME%\bin\dgmgrl %cred%@%prd% "show database %std%" > log\lag.tmp
for /f "tokens=3 delims= " %%i in ('find "Transport Lag" log\lag.tmp') do set tlag=%%i
if %tlag% neq 0 goto :wait
for /f "tokens=3 delims= " %%i in ('find "Apply Lag" log\lag.tmp') do set alag=%%i
if %alag% neq 0 goto :wait
echo Redo apply finished. Converting back to snapshot standby.
%ORACLE_HOME%\bin\dgmgrl %cred%@%prim_db% "convert database %std_db% to %role% standby"
echo ####################################################################
echo Refresh finished at %time%
echo .
echo ####################################################################
Для Linux:
# ENV part
ORACLE_SID=axtest
ORAENV_ASK=NO
. oraenv
export primary=axprd
export standby=axstd
export cred=sys/p@s$w0Rd
# Functions
function std_convert() {
mode=$1
dgmgrl $cred@$primary "convert database $standby to $mode standby"
}
function lag_check() {
alag=$(dgmgrl $cred@$primary "show database $standby" | grep "Apply Lag" | awk -F" " '{print $3}')
tlag=$(dgmgrl $cred@$primary "show database $standby" | grep "Transport Lag" | awk -F" " '{print $3}')
lag=$(($alag+$tlag))
echo $lag
}
{ echo Refresh started at; date; } | tr "\n" " "
# Actual refresh.
std_convert "physycal"
echo Waiting for apply to finish. This may take hours...
# что то тут не сработал выход из цикла (to be fixed)
while [ $(lag_check) -ge 0 ];do
lag_check
sleep 30
done
dgmgrl $cred@$primary "show database $standby" | grep "Lag"
std_convert "snapshot"
{ echo Refresh finished at; date; } | tr "\n" " "
Комментарии
Отправить комментарий