測試庫採用DataGuard同步,狀態自動切換指令碼

sundog315發表於2013-04-23

建立閃回點,並將庫開啟為讀寫模式

switchopenwrite.sh

#!/bin/sh
. /home/oracle/.bash_profile

date
sqlplus /nolog<conn / as sysdba
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
CREATE RESTORE POINT before_failover GUARANTEE FLASHBACK DATABASE;
ALTER DATABASE ACTIVATE STANDBY DATABASE;
STARTUP MOUNT FORCE;
conn / as sysdba
ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE;
ALTER DATABASE OPEN;

alter user test identified by "123456";

EXIT;
EOF

閃回資料庫,切換回DataGuard模式,並刪除閃回點

#!/bin/sh
. /home/oracle/.bash_profile

date
sqlplus /nolog<conn / as sysdba
STARTUP MOUNT FORCE;
conn / as sysdba
FLASHBACK DATABASE TO RESTORE POINT before_failover;
ALTER DATABASE CONVERT TO PHYSICAL STANDBY;
STARTUP MOUNT FORCE;
conn / as sysdba
DROP RESTORE POINT before_failover;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;
EXIT;
EOF

新增計劃任務,每日定時自動切換

30 23 * * * /home/oracle/scripts/switchstandby.sh 1>/home/oracle/scripts/switchstandby.log 2>&1
#10 12 * * * /home/oracle/scripts/switchstandby.sh 1>/home/oracle/scripts/switchstandby.log 2>&1
30 7 * * * /home/oracle/scripts/switchopenwrite.sh 1>/home/oracle/scripts/switchopenwrite.log 2>&1
#25 13 * * * /home/oracle/scripts/switchopenwrite.sh 1>/home/oracle/scripts/switchopenwrite.log 2>&1[@more@]

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

相關文章