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
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()
def recoverServers(self): serverList = serverlist.getRecoverServerList(self.backstage_db,self.backstage_tag,self.partnersType,self.backstage,self.servername) MainServers=[] MixServers=[] for server in serverList: if serverList[server]['mixflag'] == 1: MainServers.append(serverList[server]) #elif not self.big_mix_server: else: MixServers.append(serverList[server]) for serverflag in MainServers: servername=serverflag['MainName'] starttime=serverflag['starttime'] cleartime = (datetime.datetime.strptime(starttime,"%Y-%m-%d %H:%M:%S") + datetime.timedelta(hours=self.delta_hours) - datetime.timedelta(minutes=30)).strftime("%Y-%m-%d %H:%M:%S") yx,quhao = servername.split("_") serverdict = self.getUrl(yx,quhao) print serverdict if self.dianxinIp == self.liantongIp: dns_ip_name = self.dianxinIp else: dns_ip_name = serverdict['server_url'] newserver_parameter = " '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s'"%(self.game,self.language,servername,serverdict['title'],serverdict['server_url'],dns_ip_name,self.is_mobile,cleartime,self.innit_sql,self.www_dir_type,self.www_ip,self.www_port,self.www_header,self.clear_script,self.template_tar_dir,self.template_exclude_dir,self.recoverType,self.ftppath,self.deploy_special_script,self.deploy_script) self.cmd("test ! -d /app/%s_%s"%(self.game,servername),"游戏目录已经存在") self.cmd("test ! -e /app/nginx/conf/vhost/%s_%s.conf"%(self.game,servername),"nginx配置文件已存在") self.cmd("if [ $(pandora -e 'show databases' | grep -E '%s_%s$'|wc -l) != 0 ];then exit 1; fi"%(self.game,servername),"数据库已经存在") self.cmd("[ -d %s/shell ] || mkdir -p %s/shell"%(self.clientrootdir,self.clientrootdir)) try: self.ssh.put("%s/../shell/%s"%(self.curdir,self.deploy_common_script),remote_path=self.clientrootdir+"/shell") self.ssh.put("%s/../shell/%s"%(self.curdir,self.deploy_script),remote_path=self.clientrootdir+"/shell") self.ssh.put("%s/../shell/%s"%(self.curdir,self.clear_script),remote_path=self.clientrootdir+"/shell") if self.deploy_special_script.strip() != "": self.ssh.put("%s/../shell/%s"%(self.curdir,self.deploy_special_script),remote_path=self.clientrootdir+"/shell") except Exception,e1: self.statusCheck(False,str(e1)+"\nscp %s %s %s到服务器失败"%(self.deploy_script,self.clear_script,self.deploy_common_script)) print newserver_parameter try: recover_stdout = self.cmd("source /etc/profile && sh %s/shell/%s %s"%(self.clientrootdir,self.deploy_common_script,newserver_parameter), msg="部署服务器失败!") if recover_stdout.find("backstage添加失败") >= 0: logging.info("后台agent配置添加失败") if recover_stdout.find("nginx error") >= 0: logging.info("nginx 配置问题,请查看!") logging.info("开始修改主服后台...") #self.modifyBackstage(yx,quhao) logging.info("后台修改完毕!") logging.info("开始修改dns解析...") #self.dnsJiexi(serverdict['server_url_tag']) logging.info("dns解析修改完毕!") #self.bigMixServerDeploy() except Exception,e5: print "[%s] 还原异常:%s"%(serverflag,str(e5))
def recoverServers(self): serverList = serverlist.getRecoverServerList(self.backstage_db,self.backstage_tag,self.partnersType,self.backstage,self.servername) MainServers=[] MixServers=[] for server in serverList: if serverList[server]['mixflag'] == 1: MainServers.append(serverList[server]) #elif not self.big_mix_server: else: MixServers.append(serverList[server]) for serverflag in MainServers: servername=serverflag['MainName'] starttime=serverflag['starttime'] cleartime = (datetime.datetime.strptime(starttime,"%Y-%m-%d %H:%M:%S") + datetime.timedelta(hours=self.delta_hours) - datetime.timedelta(minutes=30)).strftime("%Y-%m-%d %H:%M:%S") yx,quhao = servername.split("_") serverdict = self.getUrl(yx,quhao) print serverdict if self.dianxinIp == self.liantongIp: dns_ip_name = self.dianxinIp else: dns_ip_name = serverdict['server_url'] newserver_parameter = " '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s'"%(self.game,self.language,servername,serverdict['title'],serverdict['server_url'],dns_ip_name,self.is_mobile,cleartime,self.innit_sql,self.www_dir_type,self.www_ip,self.www_port,self.www_header,self.clear_script,self.template_tar_dir,self.template_exclude_dir,self.recoverType,self.ftppath,self.deploy_special_script,self.deploy_script) self.cmd("test ! -d /app/%s_%s"%(self.game,servername),"游戏目录已经存在") self.cmd("test ! -e /app/nginx/conf/vhost/%s_%s.conf"%(self.game,servername),"nginx配置文件已存在") self.cmd("if [ $(pandora -e 'show databases' | grep -E '%s_%s$'|wc -l) != 0 ];then exit 1; fi"%(self.game,servername),"数据库已经存在") self.cmd("[ -d %s/shell ] || mkdir -p %s/shell"%(self.clientrootdir,self.clientrootdir)) try: self.ssh.put("%s/../shell/%s"%(self.curdir,self.deploy_common_script),remote_path=self.clientrootdir+"/shell") self.ssh.put("%s/../shell/%s"%(self.curdir,self.deploy_script),remote_path=self.clientrootdir+"/shell") self.ssh.put("%s/../shell/%s"%(self.curdir,self.clear_script),remote_path=self.clientrootdir+"/shell") if self.deploy_special_script.strip() != "": self.ssh.put("%s/../shell/%s"%(self.curdir,self.deploy_special_script),remote_path=self.clientrootdir+"/shell") except Exception,e1: self.statusCheck(False,str(e1)+"\nscp %s %s %s到服务器失败"%(self.deploy_script,self.clear_script,self.deploy_common_script)) print newserver_parameter try: recover_stdout = self.cmd("source /etc/profile && sh %s/shell/%s %s"%(self.clientrootdir,self.deploy_common_script,newserver_parameter), msg="部署服务器失败!") if recover_stdout.find("backstage添加失败") >= 0: logging.info("后台agent配置添加失败") if recover_stdout.find("nginx error") >= 0: logging.info("nginx 配置问题,请查看!") logging.info("开始修改主服后台...") self.modifyBackstage(yx,quhao) logging.info("后台修改完毕!") logging.info("开始修改dns解析...") self.dnsJiexi(serverdict['server_url_tag']) logging.info("dns解析修改完毕!") self.bigMixServerDeploy() except Exception,e5: print "[%s] 还原异常:%s"%(serverflag,str(e5))
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