コード例 #1
0
ファイル: recoverByMysql.py プロジェクト: AmiLiY/astoptool
def dnsChange(server,ip):
    wips = getip.getServerWip(ip)
    for level in range(len(wips)):
        dnslevel = level + 1
        if ismobile:
            if allservers[server]["mixflag"] == 1:
                executeDns(state.game,server,wips[level],dnslevel)
        else:
            executeDns(state.game,server,wips[level],dnslevel)
コード例 #2
0
ファイル: recoverByMysql.py プロジェクト: AmiLiY/astoptool
def recoverByMysql(failurIptemp,recoverDate,recoverfile):
    global recoverIpSsh,failurIpSsh,failurIpSshAstd,mysqldir,failurIp,curdir,recovermysqldir,backup_date,filename,recoverdate,nowdate,allservers,database_list,mysql_recover_dir,backstage_interface_url,header,ismobile,dnsgame
    dnsgame = gameOption("dns_game",state.game)
    backstage_interface_url = gameOption("backstage_interface_url")
    header = gameOption("backstage_header")
    backstageIp = gameOption("backstage")
    backstageIpSsh = ssh.ssh(backstageIp,user="******")
    backstageDb = gameOption("backstage_db")
    headTag = gameOption("backstage_tag")
    ismobile = gameOption("is_mobile",type="bool")
    if ismobile:
        partnersType = 2
    else:
        partnersType = 1
    failurIp = failurIptemp
    curdir = os.path.abspath(os.path.dirname(__file__))
    filename = recoverfile
    f = open(filename).readlines()
    database_list = []
    for i in f:
        if i.strip() == "":
            continue
        i_split = i.split("@")
        database_list.append(i_split[0].strip())
    project = state.game
    backup_date = recoverDate
    mysql_recover_dir = "/app/opbak/mysqlrecover"
    recoverdate = datetime.datetime.strptime(backup_date,"%Y-%m-%d").strftime("%Y%m%d")
    nowdate = datetime.datetime.now().strftime("%Y-%m-%d")
    failurIpSsh = ssh.ssh(failurIp,user="******")
    failurIpSshAstd = ssh.ssh(failurIp)
    mysqldir = cmd(failurIpSsh,"grep '^innodb_data_home_dir' /etc/my.cnf | cut -d '=' -f 2|xargs echo").strip()
    #recovermysqldir = cmd(recoverIpSsh,"grep '^innodb_data_home_dir' /etc/my.cnf | cut -d '=' -f 2|xargs echo").strip()
    allservers = serverlist.getRecoverServerList(backstageDb,headTag,partnersType,backstageIp,failurIp)
    wip = getip.getServerWip(failurIp)
    if len(wip) >0 :
        olddianxinip = wip[0]
    else:
        raise Exception("获取外网ip失败!")
    #游戏还原
    createBinlog()
    threads = []
    for line in f:
        s = line.split("@")
        servername = s[0].strip()
        ip = s[1].strip()
        t = threading.Thread(target=recoverByGame,args=(servername,ip,))
        threads.append(t)
        t.start()
    for i in threads:
        i.join()
コード例 #3
0
ファイル: recoverByProject.py プロジェクト: AmiLiY/astoptool
def recoverByProject(failurIptemp,recoverIptemp):
    global recoverIpSsh,failurIpSsh,recoverIpSshAstd,mysqldir,failurIp,recoverIp,failurIpSshAstd,allservers,wips,ismobile,dianxinIp,liantongIp,header,backstage_interface_url,curdir,recovermysqldir,dnsgame
    dnsgame = gameOption("dns_game",default=state.game)
    failurIp = failurIptemp
    recoverIp = recoverIptemp
    curdir = os.path.abspath(os.path.dirname(__file__))
    project = state.game
    recoverIpSsh = ssh.ssh(recoverIp,user="******")
    failurIpSsh = ssh.ssh(failurIp,user="******")
    recoverIpSshAstd = ssh.ssh(recoverIp)
    failurIpSshAstd = ssh.ssh(failurIp)
    mysqldir = cmd(failurIpSsh,"grep '^innodb_data_home_dir' /etc/my.cnf | cut -d '=' -f 2|xargs echo").strip()
    recovermysqldir = cmd(recoverIpSsh,"grep '^innodb_data_home_dir' /etc/my.cnf | cut -d '=' -f 2|xargs echo").strip()
    stop_service()
    donwloadMysql()
    downloadNginx()
    download(state.game)
    logCopy()
    change_configfile()
    start_service()
    startGame()
    backstageDB = gameOption("backstage_db")
    headTag = gameOption("backstage_tag")
    ismobile = gameOption("is_mobile",type="bool")
    if ismobile:
        partnersType = 2
    else:
        partnersType = 1
    backstageIp =gameOption("backstage")
    header = {"host":gameOption("backstage_header")}
    backstage_interface_url = gameOption("backstage_interface_url")
    allservers = serverlist.getRecoverServerList(backstageDB,headTag,partnersType,backstageIp,failurIp)
    wips = getip.getServerWip(recoverIp)
    if len(wips) == 0:
        print "ERROR: 获取外网ip失败!"
    else:
        dianxinIp = wips[0]
        if len(wips) == 2:
            liantongIp = wips[1]
        else:
            liantongIp = wips[0]
    backstageChange()
    dnsChange()
    faileDirs = cmd(failurIpSshAstd,"find /app/ -maxdepth 1 -type d").split("\n")
    recoverDirs = cmd(recoverIpSshAstd,"find /app/ -maxdepth 1 -type d").split("\n")
    d1 = set(faileDirs).difference(set(recoverDirs))
    if len(d1) > 0:
        print "故障机器目录如下,请确认是否已完全迁移!"
        print d1
コード例 #4
0
ファイル: recoverByMysql.py プロジェクト: AmiLiY/astoptool
def recover(server,curssh,recoverSshAstd,ip):
    servername = state.game + "_" + server
    cmd(curssh,"test ! -d /app/%s"%servername)
    cmd(curssh,"rsync -av %s:/app/%s --exclude=logs --exclude=temp --exclude=fight /app/"%(failurIp,servername))
    logs = cmd(failurIpSsh,"find /app/%s -type f | grep %s"%(servername,nowdate))
    logsplit = logs.split("\n")
    logsplit.remove("")
    for line in logsplit:
        dir = os.path.dirname(line)
        cmd(recoverSshAstd,"mkdir -p %s"%dir)
        cmd(curssh,"rsync -av %s:%s %s"%(failurIp,line,line))
    cmd(recoverSshAstd,"cd /app/%s/backend && mkdir fight temp"%servername)
    cmd(curssh,"rsync -av %s:%s/%s/%s* /app/%s/"%(failurIp,mysql_recover_dir,backup_date,servername,servername))
    cmd(curssh,"/usr/bin/bzip2 -d /app/%s/%s_%s.sql.bz2"%(servername,servername,recoverdate))
    cmd(curssh,"pandora --update -e 'create database %s'"%servername)
    cmd(curssh,"pandora --update %s < /app/%s/%s_%s.sql"%(servername,servername,servername,recoverdate))
    cmd(curssh,"pandora --update %s < /app/%s/%s.binlog"%(servername,servername,servername))
    rwip = getip.getServerWip(ip)
    failurewip = getip.getServerWip(failurIp)
    if len(rwip) >0:
        print "%s:获取外网ip失败!"%ip
    else:
        newdianxinip = rwip[0]
        cmd(recoverSshAstd,"sed -i 's/%s/%s/g' /app/%s_*/www*/Config.xml"%(failurewip[0],rwip[0],servername))
コード例 #5
0
ファイル: recover.py プロジェクト: AmiLiY/astoptool
 def getWip(self):
     '''dns解析'''
     try:
         wip = getip.getServerWip(self.ip)
         logging.info("外网ip获取结果为:" + str(wip))
         if len(wip) == 0:
             self.statusCheck(False,"获取外网ip失败")
         if len(wip) >= 1:
             self.dianxinIp = wip[0]
             self.liantongIp = wip[0]
             self.xianluType = 1
         if len(wip) >= 2:
             self.liantongIp = wip[1]
             self.xianluType = 2
         if len(wip) == 1:
             self.dns_ip_name = wip[0]
         else:
             self.dns_ip_name = self.server_url
     except Exception,e1:
         self.statusCheck(False,"%s\n获取外网ip失败"%(str(e1)))
コード例 #6
0
 def getWip(self):
     '''dns解析'''
     try:
         wip = getip.getServerWip(self.ip)
         logging.info("外网ip获取结果为:" + str(wip))
         if len(wip) == 0:
             self.statusCheck(False, "获取外网ip失败")
         if len(wip) >= 1:
             self.dianxinIp = wip[0]
             self.liantongIp = wip[0]
             self.xianluType = 1
         if len(wip) >= 2:
             self.liantongIp = wip[1]
             self.xianluType = 2
         if len(wip) == 1:
             self.dns_ip_name = wip[0]
         else:
             self.dns_ip_name = self.server_url
     except Exception, e1:
         self.statusCheck(False, "%s\n获取外网ip失败" % (str(e1)))
コード例 #7
0
def backstageChange(server,ip):
    wip = getip.getServerWip(ip)
    if len(wip) == 0:
        print "%s %s 获取外网失败!"%(server,ip)
        return 
    elif len(wip) == 1:
        dianxinIp = wip[0]
        liantongIp = dianxinIp
    else:
        dianxinIp = wip[0]
        liantongIp = wip[1]
    if int(allservers[server]["mixflag"]) == 1:
        data = {}
        data["servername"] = allservers[server]["servername"].replace("_","_S")
        data["n_ip"] = ip
        data["w_ip"] = dianxinIp
        data["cnc_ip"] = liantongIp
        backstageHeader = {"host":header}
        result = backstage.upBackstage(backstage_interface_url,data,backstageHeader)
        if result["status"]:
            print "%s 修改后台成功!"%server
        else:
            print "%s 修改后台失败!MSG:%s"%(server,result["msg"])
    pass
コード例 #8
0
def change_configfile():
    oldWip = getip.getServerWip(failurIp)[0]
    recoverWip = getip.getServerWip(recoverIp)[0]
    cmd(
        recoverIpSshAstd, "sed -i 's/%s/%s/g' /app/%s_*/www*/Config.xml" %
        (oldWip, recoverWip, state.game))
コード例 #9
0
ファイル: recoverByProject.py プロジェクト: AmiLiY/astoptool
def change_configfile():
    oldWip = getip.getServerWip(failurIp)[0]
    recoverWip = getip.getServerWip(recoverIp)[0]
    cmd(recoverIpSshAstd,"sed -i 's/%s/%s/g' /app/%s_*/www*/Config.xml"%(oldWip,recoverWip,state.game))