ceshi
作者:互联网
whether_primary={{whether_primary}} if [ $whether_primary = "yes" ];then su - oracle <<EON sqlplus -s / as sysdba <<EOF spool /tmp/oracle_abort.log set pages 0 set head off set feed off set echo off shutdown abort spool off exit; EOF EON ERROR="ORA-" abort_result=`cat /tmp/oracle_abort.log` a=$(echo $abort_result | grep "${ERROR}") if [[ "$a" != "" ]] then echo '<scriptResult>{"message":"abort database failed please go to /tmp/oracle_abort.log ","state":"failed","result":"False"}</scriptResult>' else su - oracle <<EON sqlplus -s / as sysdba <<EOF spool /tmp/oracle_startup.log set pages 0 set head off set feed off set echo off startup spool off exit; EOF EON startup_result=`cat /tmp/oracle_startup.log` b=$(echo $startup_result | grep "${ERROR}") if [[ "$b" != "" ]] then echo '<scriptResult>{"message":"startup mount database failed ,For more information, please go to /tmp/oracle_startup.log ","state":"failed","result":"False"}</scriptResult>' else rm -rf /tmp/oracle_*.log echo '<scriptResult>{"message":"","state":"success","result":"True"}</scriptResult>' fi fi else su - oracle <<EON sqlplus -s / as sysdba <<EOF spool /tmp/oracle_abort.log set pages 0 set head off set feed off set echo off shutdown abort spool off exit; EOF EON ERROR="ORA-" abort_result=`cat /tmp/oracle_abort.log` a=$(echo $abort_result | grep "${ERROR}") if [[ "$a" != "" ]] then echo '<scriptResult>{"message":"shutdown database failed ,For more information, please go to /tmp/oracle_abort.log ","state":"failed","result":"False"}</scriptResult>' else su - oracle <<EON sqlplus -s / as sysdba <<EOF spool /tmp/oracle_mount.log set pages 0 set head off set feed off set echo off startup mount spool off exit; EOF EON startup_result=`cat /tmp/oracle_mount.log` b=$(echo $startup_result | grep "${ERROR}") if [[ "$b" != "" ]] then echo '<scriptResult>{"message":"startup mount database failed ,For more information, please go to /tmp/oracle_mount.log ","state":"failed","result":"False"}</scriptResult>' else su - oracle <<EON sqlplus -s / as sysdba <<EOF spool /tmp/oracle_recover.log set pages 0 set head off set feed off set echo off alter database recover managed standby database finish; spool off exit; EOF EON recover_result=`cat /tmp/oracle_recover.log` c=$(echo $recover_result | grep "${ERROR}") if [[ "$c" != "" ]] then echo '<scriptResult>{"message":" alter database recover managed standby failed ,For more information, please go to /tmp/oracle_recover.log ","state":"failed","result":"False"}</scriptResult>' else su - oracle <<EON sqlplus -s / as sysdba <<EOF spool /tmp/oracle_switchover.log set pages 0 set head off set feed off set echo off alter database commit to switchover to primary; spool off exit; EOF EON switchover_result=`cat /tmp/oracle_switchover.log` d=$(echo $switchover_result | grep "${ERROR}") if [[ "$d" != "" ]] then echo echo '<scriptResult>{"message":" alter database commit to switchover to primary failed ,For more information, please go to /tmp/oracle_switchover.log ","state":"failed","result":"False"}</scriptResult>' else su - oracle <<EON sqlplus -s / as sysdba <<EOF alter database open; EOF lsnrctl stop lsnrctl start EON if [ $? -eq 0 ];then rm -rf /tmp/oracle_*.log echo '<scriptResult>{"message":"","state":"success","result":"True"}</scriptResult>' else echo '<scriptResult>{"message":' '"'"listen start failed"'"' ',"state":"failed","result":"False"}</scriptResult>' fi fi fi fi fi fi
from ..models import * from lxml import etree import base64 import json db_server_id = componentInput["db_server_id"] apply_server_id = componentInput["apply_server_id"] falcon_server_id = componentInput["falcon_server_id"] state = "failed" message="未知错误" result = False db_server_info = {} apply_server_info = {} falcon_server_info = {} def parsexml(xmlinfo): db_info = {} if 'root' and 'param' in xmlinfo: info = etree.XML(xmlinfo) info = info.xpath("//root/param") for i in info: db_info[i.attrib["variable_name"]] = i.attrib["param_value"] return db_info if db_server_id and apply_server_id and falcon_server_id: # 飞康服务器参数 util_obj = UtilsManage.objects.exclude(state="9").filter(id=int(falcon_server_id)) if util_obj.exists(): util = util_obj[0] ip = "" user = "" password = "" content = util.content doc = etree.XML(content) try: ip = doc.xpath('//FalconHost/text()')[0] except: pass try: user = doc.xpath('//FalconUser/text()')[0] except: pass try: password = base64.b64decode(doc.xpath('//FalconPasswd/text()')[0]).decode() except: pass falcon_server_info["ip"] = ip falcon_server_info["user"] = user falcon_server_info["password"] = password # 数据库服务器参数 db_obj = HostsManage.objects.exclude(state='9').filter(id=int(db_server_id)) if db_obj.exists(): db = db_obj[0] db_info = parsexml(db.config) mount_dev = db_info.get("mount_dev") RPO = db_info.get("RPO") svdevid = db_info.get("svdevid") clientid = db_info.get("clientid") mountdir = db_info.get("mountdir") whether_primary = db_info.get("whether_primary") ip = db.host_ip user = db.username password = db.password db_server_info["ip"] = ip db_server_info["user"] = user db_server_info["password"] = password db_server_info["mount_dev"] = mount_dev db_server_info["RPO"] = RPO db_server_info["svdevid"] = svdevid db_server_info["clientid"] = clientid db_server_info["mountdir"] = mountdir db_server_info["whether_primary"] = whether_primary # 应用端服务器参数 apply_obj = HostsManage.objects.exclude(state='9').filter(id=int(apply_server_id)) if apply_obj.exists(): apply = apply_obj[0] apply_info = parsexml(apply.config) ip = apply.host_ip user = apply.username password = apply.password app_type = apply_info.get("app_type") apply_server_info["ip"] = ip apply_server_info["user"] = user apply_server_info["password"] = password apply_server_info["app_type"] = app_type state = "success" message = "" result = True db_server_info = json.dumps(db_server_info) apply_server_info = json.dumps(apply_server_info) falcon_server_info = json.dumps(falcon_server_info) componentOutput["db_server_info"] = db_server_info componentOutput["apply_server_info"] = apply_server_info componentOutput["falcon_server_info"] = falcon_server_info componentOutput["state"] = state componentOutput["message"] = message componentOutput["result"] = result
标签:info,ceshi,db,server,failed,state,apply 来源: https://www.cnblogs.com/zhangguosheng1121/p/15540800.html