def conf_rst(tar_name): if os.path.exists("/data/oper/confBak/%s" % tar_name): print blue(">>>>解包配置文件...") local("cd /data/oper/confBak && rm -rf apps && tar -xvf %s" % tar_name) for app in applist: instList = getConfPath(rulesPath, app) for inst in instList: inst_no = inst[0] ip = inst[1] port = inst[2] rmtPath = inst[3] + '../conf/' with settings(host_string=ip): localPath = "%s/apps/%s/" % (confBakPath, app) local_folder_name = "conf-%s-%s-%s" % (app, inst_no, port) # 个性化各台机器配置 - 可选 mod_sigle_inst(app, ip, port, localPath + local_folder_name, "server.properties", inst_no) mod_sigle_inst(app, ip, port, localPath + local_folder_name, "system.properties", inst_no) # 建立远程路径 run("mkdir -p %s" % inst[3]) run("cd %s../ && mkdir -p ./conf/" % (inst[3])) put(localPath + local_folder_name + "/*", rmtPath) local("cd /data/oper/confBak && rm -rf apps") print blue("还原完毕!") else: print "并没有找到包 %s" % tar_name
def confByApp(app, fName): rules = getConfPath(rulesPath, app) # [('1', '10.10.1.9', 8080, '/data/foundation/ver/'), ('2', '10.10.1.8', 8080, '/data/foundation/ver/')] print rules for rule in rules: instId = rule[0] ip = rule[1] port = rule[2] toPath = rule[3] + '../conf/' confByInst(app, ip, port, confModPath, fName, toPath, instId)
def conf_bak(): print blue("开始备份所有配置文件...") for app in applist: instList = getConfPath(rulesPath, app) for inst in instList: inst_no = inst[0] ip = inst[1] port = inst[2] rmtPath = inst[3] + '../conf/*' with settings(host_string=ip): localPath = "%s/apps/%s/conf-%s-%s-%s" % (confBakPath, app, app, inst_no, port) local("mkdir -p %s" % localPath) get(rmtPath, localPath) backTarName = 'confs-' + time.strftime('%Y%m%d%H%m%S', time.localtime(time.time())) local("cd %s&&tar -rf %s.tar ./apps/* && rm -rf ./apps" % (confBakPath, backTarName)) print blue("备份完毕:\n %s.tar 保存在:%s 中" % (backTarName, confBakPath))
def tomcat_xml_rst(tar_name): if os.path.exists("/data/oper/confBak/%s" % tar_name): print blue(">>>>解包配置文件...") local("cd /data/oper/confBak && rm -rf tomcats && tar -xvf %s" % tar_name) for app in applist: instList = getConfPath(rulesPath, app) for inst in instList: inst_no = inst[0] ip = inst[1] port = inst[2] rmtPath = inst[3] + '../tomcat/conf/' with settings(host_string=ip): localPath = "%s/tomcats/%s/" % (confBakPath, app) local_name = "server.xml-%s-%s-%s" % (app, inst_no, port) # 建立远程路径 run("mkdir -p %s" % inst[3]) run("cd %s../ && mkdir -p ./tomcat/conf/" % (inst[3])) put(localPath + local_name, rmtPath + "server.xml") local("cd /data/oper/confBak && rm -rf tomcats") print blue("还原完毕!") else: print "并没有找到包 %s" % tar_name
def startAllHostOf(app): targets = getConfPath(rulesPath, app) if (targets and len(targets) >= 0): for target in targets: startSingleHost(target)