s_nopass_str = mysql.GetSingleValue(mysql_conn, s_str) logger.info("The standby database is: " + s_nopass_str + ", the id is: " + str(sta_id)) s_conn = oracle.ConnectOracleAsSysdba(s_conn_str) try: common.operation_lock(mysql_conn, group_id, 'SNAPSHOT_STOP') common.init_op_instance(mysql_conn, group_id, 'SNAPSHOT_STOP') #初始化切换实例 if s_conn is None: logger.error("Connect to standby database error, exit!!!") common.update_op_reason(mysql_conn, group_id, 'SNAPSHOT_STOP', '连接数据库失败') common.update_op_result(mysql_conn, group_id, 'SNAPSHOT_STOP', '-1') sys.exit(2) common.log_dg_op_process(mysql_conn, group_id, 'SNAPSHOT_STOP', '准备退出演练模式', 10, 2) res = stop_mrp(mysql_conn, group_id, s_conn, s_conn_str, sta_id) if res == 0: update_mrp_status(mysql_conn, sta_id) common.update_op_result(mysql_conn, group_id, 'SNAPSHOT_STOP', '0') finally: common.operation_unlock(mysql_conn, group_id, 'SNAPSHOT_STOP')
'SWITCHOVER', '开始切换IP...', 92, 2) logger.info("开始切换IP...") shift_vip(mysql_conn, group_id, is_p_rac, is_s_rac, pri_id, sta_id, dg_pid, dg_sid) common.log_dg_op_process(mysql_conn, group_id, 'SWITCHOVER', 'IP切换结束', 95, 2) update_switch_flag(mysql_conn, group_id) common.gen_alert_oracle(sta_id, 1) # generate alert common.update_op_result(mysql_conn, group_id, 'SWITCHOVER', '0') else: common.update_op_result(mysql_conn, group_id, 'SWITCHOVER', res_2p) common.log_dg_op_process(mysql_conn, group_id, 'SWITCHOVER', '切换失败,请通过相关日志查看原因!', 90, 2) else: common.update_op_result(mysql_conn, group_id, 'SWITCHOVER', res_2s) common.log_dg_op_process(mysql_conn, group_id, 'SWITCHOVER', '切换失败,请通过相关日志查看原因!', 50, 2) except Exception, e: pass except Exception, e: pass finally: common.operation_unlock(mysql_conn, group_id, 'SWITCHOVER')
sys.exit(2) s_str = """select concat(username, '/', password, '@', host, ':', port, '/', dsn) from db_servers_oracle where id=%s """ % ( sta_id) s_conn_str = mysql.GetSingleValue(mysql_conn, s_str) s_str = """select concat(username, '/', password, '@', host, ':', port, '/', dsn) from db_servers_oracle where id=%s """ % ( sta_id) s_nopass_str = mysql.GetSingleValue(mysql_conn, s_str) logger.info("The standby database is: " + s_nopass_str + ", the id is: " + str(sta_id)) s_conn = oracle.ConnectOracleAsSysdba(s_conn_str) if s_conn is None: logger.error("Connect to standby database error, exit!!!") sys.exit(2) else: try: common.operation_lock(mysql_conn, group_id, 'MRP_STOP') common.log_dg_op_process(mysql_conn, group_id, 'MRP_STOP', '准备开始停止MRP进程。', 10, 2) res = stop_mrp(mysql_conn, group_id, s_conn, s_conn_str, sta_id) if res == 0: update_mrp_status(mysql_conn, sta_id) finally: common.operation_unlock(mysql_conn, group_id, 'MRP_STOP') None
try: common.log_dg_op_process(mysql_conn, group_id, 'FAILOVER', '准备执行灾难切换', 10, 2) res = failover2primary(mysql_conn, group_id, s_conn, s_conn_str, sta_id) if res == 0: #shift vip if is_shift == 1: common.log_dg_op_process(mysql_conn, group_id, 'FAILOVER', '开始绑定VIP...', 92, 2) logger.info("开始绑定VIP...") res = bind_ip(mysql_conn, group_id, sta_id, dg_pid, "bind") if res == -1: common.log_dg_op_process(mysql_conn, group_id, 'FAILOVER', '绑定VIP失败', 95, 2) else: common.log_dg_op_process(mysql_conn, group_id, 'FAILOVER', '绑定VIP成功', 95, 2) common.log_dg_op_process(mysql_conn, group_id, 'FAILOVER', 'VIP绑定结束', 95, 2) update_switch_flag(mysql_conn, group_id) common.gen_alert_oracle(sta_id, 1) # generate alert common.update_op_result(mysql_conn, group_id, 'FAILOVER', '0') except Exception, e: pass except Exception, e: pass finally: common.operation_unlock(mysql_conn, group_id, 'FAILOVER')