ITPub博客

首页 > 数据库 > Oracle > 测试库采用DataGuard同步,状态自动切换脚本

测试库采用DataGuard同步,状态自动切换脚本

原创 Oracle 作者:sundog315 时间:2013-04-23 08:38:58 0 删除 编辑

创建闪回点,并将库打开为读写模式

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/,如需转载,请注明出处,否则将追究法律责任。

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

注册时间:2010-01-05

  • 博文量
    126
  • 访问量
    502722