def parseCommandLine(): """ """ try: opts, args = getopt.getopt(sys.argv[1:], "U:P:G:l:?", ["help", "dws_mode", "vc_mode"]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError( ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_opts g_opts = CmdOptions() for (key, value) in opts: if (key == "-?" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_opts.clusterUser = value elif (key == "-P"): g_opts.dbInitParams.append(value) elif (key == "-l"): g_opts.logFile = os.path.realpath(value) elif (key == "--dws_mode"): g_opts.dws_mode = True elif (key == "--vc_mode"): g_opts.vc_mode = True Parameter.checkParaVaild(key, value)
def parseCommandLine(): """ function: Parse command line and save to global variable input : NA output: NA """ try: (opts, args) = getopt.getopt(sys.argv[1:], "t:U:l:", ["help"]) except Exception as e: # print help information usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) # parse parameter for (key, value) in opts: if (key == "--help"): usage() sys.exit(0) elif (key == "-t"): g_opts.action = value elif (key == "-l"): g_opts.logFile = value elif (key == "-U"): g_opts.user = value Parameter.checkParaVaild(key, value)
def __checkParameters(self): """ function: check input parameters input : NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "U:R:l:du", ["help"]) except getopt.GetoptError as e: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) logFile = "" for key, value in opts: if (key == "-U"): self.user = value elif (key == "-R"): self.installPath = value elif (key == "-l"): logFile = value elif (key == "-d"): self.cleanData = True elif (key == "-u"): self.cleanUser = True elif (key == "--help"): self.usage() sys.exit(0) else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % key) Parameter.checkParaVaild(key, value) if (self.user == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".") if (self.installPath == ""): raise Exception(ErrorCode.GAUSS_500["GAUSS_50001"] % 'R' + ".") if (logFile == ""): logFile = DefaultValue.getOMLogPath(DefaultValue.LOCAL_LOG_FILE, "", self.installPath, "") self.logger = GaussLog(logFile, "CheckUninstall") self.logger.debug("The installation path of program: " + self.installPath) self.logger.debug("The parameter of clean user is: %s." % self.cleanUser) self.logger.debug("The parameter of clean data is: %s." % self.cleanData)
def main(): """ function: main function input : NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "U:C:D:i:l:h", ["help"]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) logFile = "" dataParams = [] instanceIds = [] for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): clusterUser = value elif (key == "-D"): dataParams.append(value) elif (key == "-l"): logFile = os.path.realpath(value) elif (key == "-i"): if (value.isdigit()): instanceIds.append(int(value)) else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] % "i") Parameter.checkParaVaild(key, value) # check if user exist and is the right user DefaultValue.checkUser(clusterUser) # check log dir if (logFile == ""): logFile = DefaultValue.getOMLogPath(DefaultValue.LOCAL_LOG_FILE, clusterUser, "", "") try: checker = CheckNodeEnv(logFile, clusterUser, dataParams, instanceIds) checker.run() sys.exit(0) except Exception as e: GaussLog.exitWithError(str(e))
def checkParameters(self): """ function: Check input parameters input : NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "t:U:R:l:X:M:T", ["help", "delete-data"]) except getopt.GetoptError as e: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) for key, value in opts: if (key == "-U"): self.user = value elif (key == "-R"): self.installPath = value elif (key == "-l"): self.logFile = value elif (key == "--help"): self.usage() sys.exit(0) elif (key == "-T"): self.installflag = True elif key == "--delete-data": self.keepData = False elif key == "-M": self.method = value elif key == "-t": self.action = value else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % key) Parameter.checkParaVaild(key, value) if (self.user == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".") if (self.installPath == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'R' + ".") self.mpprcFile = DefaultValue.getMpprcFile() if (self.logFile == ""): self.logFile = DefaultValue.getOMLogPath( DefaultValue.LOCAL_LOG_FILE, self.user, self.installPath)
def parseCommandLine(): """ function: parseCommandLine input: NA output: NA """ try: paraLine = sys.argv[1] paraLine = DefaultValue.encodeParaline(paraLine, DefaultValue.BASE_DECODE) paraLine = paraLine.strip() paraList = paraLine.split("*==SYMBOL==*") opts, args = getopt.getopt( paraList[1:], "U:C:D:T:P:l:hX:", ["help", "alarm=", "gucXml", "vc_mode", "dws-mode"]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_opts g_opts = CmdOptions() for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_opts.clusterUser = value elif (key == "-D"): g_opts.dataGucParams.append(value) elif (key == "-T"): g_opts.configType = value elif (key == "-P"): g_opts.clusterStaticConfigFile = value elif (key == "-l"): g_opts.logFile = os.path.realpath(value) elif (key == "--alarm"): g_opts.alarmComponent = value elif (key == "--gucXml"): g_opts.gucXml = True elif (key == "--vc_mode"): g_opts.vcMode = True elif (key == "--dws-mode"): g_opts.dws_mode = True elif key == "-X": g_opts.clusterConf = os.path.realpath(value) Parameter.checkParaVaild(key, value)
def parseCommandLine(): """ function: Parse command line and save to global variables input : NA output: NA """ try: # Resolves the command line opts, args = getopt.getopt(sys.argv[1:], "t:X:l:U:V?", ["help", "log-file=", "xmlfile=", "MTUvalue=", "hostname=", "check-os", "version"]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_opts global g_check_os g_opts = CmdOptions() # Output help information and exit for (key, value) in opts: if (key == "-?" or key == "--help"): usage() sys.exit(0) elif (key == "-V" or key == "--version"): print(("%s %s" % (sys.argv[0].split("/")[-1], VersionInfo.COMMON_VERSION))) sys.exit(0) elif (key == "-t"): g_opts.action = value elif (key == "-U"): g_opts.user = value elif (key == "--check-os"): g_check_os = True elif (key == "-l" or key == "--log-file"): g_opts.logFile = os.path.realpath(value) elif (key == "--MTUvalue"): g_opts.mtuValue = value elif (key == "--hostname"): g_opts.hostname = value elif (key == "-X"): g_opts.confFile = value # check para vaild Parameter.checkParaVaild(key, value)
def parseCommandLine(): """ parse command line input : NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "U:R:C:l:X:", ["help"]) except getopt.GetoptError as e: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_opts g_opts = CmdOptions() parameter_map = { "-U": g_opts.userInfo, "-R": g_opts.installPath, "-l": g_opts.logFile, "-X": g_opts.clusterConfig } parameter_keys = parameter_map.keys() for key, value in opts: if (key == "--help"): usage() sys.exit(0) elif (key in parameter_keys): parameter_map[key] = value elif (key == "-C"): g_opts.confParameters.append(value) else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % value) Parameter.checkParaVaild(key, value) g_opts.userInfo = parameter_map["-U"] g_opts.installPath = parameter_map["-R"] if os.path.islink( g_opts.installPath) or not os.path.exists(g_opts.installPath): versionFile = VersionInfo.get_version_file() commitid = VersionInfo.get_version_info(versionFile)[2] g_opts.installPath = g_opts.installPath + "_" + commitid g_opts.logFile = parameter_map["-l"] g_opts.clusterConfig = parameter_map["-X"]
def parseCommandLine(self): """ function: Check input parameters input : NA output: NA """ try: opts, args = getopt.getopt( sys.argv[1:], "U:D:R:l:t:h?", ["help", "security-mode=", "cluster_number="]) except getopt.GetoptError as e: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) for key, value in opts: if key == "-U": self.user = value elif key == "-D": self.dataDir = value elif key == "-t": self.time_out = int(value) elif key == "-l": self.logFile = value elif key == "-R": self.installPath = value elif key == "--help" or key == "-h" or key == "-?": self.usage() sys.exit(0) elif key == "--security-mode": self.security_mode = value elif key == "--cluster_number": self.cluster_number = value else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % key) Parameter.checkParaVaild(key, value) if self.user == "": GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".") if self.logFile == "": self.logFile = DefaultValue.getOMLogPath( DefaultValue.LOCAL_LOG_FILE, self.user, self.installPath)
def __checkParameters(self): """ function: Check parameter from command line input : NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "U:l:", ["help"]) except getopt.GetoptError as e: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) logFile = "" for key, value in opts: if (key == "-U"): self.user = value elif (key == "-l"): logFile = value elif (key == "--help"): self.usage() sys.exit(0) else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % key) Parameter.checkParaVaild(key, value) if (self.user == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".") try: DefaultValue.checkUser(self.user, False) except Exception as e: GaussLog.exitWithError(str(e)) if (logFile == ""): logFile = DefaultValue.getOMLogPath(DefaultValue.LOCAL_LOG_FILE, self.user, "") self.logger = GaussLog(logFile, "CleanOsUser") self.logger.ignoreErr = True
def parseCommandLine(self): """ function: Check parameter from command line input : NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "t:u:X:l:f:Q:P:", ["help"]) except Exception as e: self.usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) for (key, value) in opts: if (key == "--help"): self.usage() sys.exit(0) elif (key == "-t"): self.action = value elif (key == "-u"): self.user = value elif (key == "-X"): self.clusterConfig = value elif (key == "-l"): self.logFile = os.path.realpath(value) elif (key == "-f"): self.tmpFile = value elif key == "-Q": self.clusterToolPath = value elif key == "-P": self.userHome = value else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % key) Parameter.checkParaVaild(key, value)
def parseCommandLine(): """ function: Parse command line and save to global variable input: NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "t:R:U:v:l:X:N:", ["help"]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) for (key, value) in opts: if (key == "--help"): usage() sys.exit(0) elif (key == "-t"): g_opts.action = value elif (key == "-R"): g_opts.appPath = value elif (key == "-U"): g_opts.user = value elif (key == "-l"): g_opts.logFile = os.path.realpath(value) elif (key == "-X"): g_opts.xmlFile = os.path.realpath(value) elif (key == "-v"): g_opts.upgrade_version = value elif (key == "-N"): g_opts.newAppPath = value else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % key) Parameter.checkParaVaild(key, value)
def parseCommandLine(): """ function: parse command line """ try: opts, args = getopt.getopt( sys.argv[1:], "U:X:l:r", ["remove-ip=", "help", "dws-mode", "add-ip="]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_opts g_opts = CmdOptions() for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_opts.clusterUser = value elif (key == "-X"): g_opts.clusterConf = value elif (key == "-l"): g_opts.logFile = value elif (key == "-r"): g_opts.ignorepgHbaMiss = True elif (key == "--remove-ip"): g_opts.removeIps.append(value) elif (key == "--dws-mode"): g_opts.dws_mode = True elif (key == "--add-ip"): g_opts.addIps = value.split(',') Parameter.checkParaVaild(key, value)
def parseCommandLine(): """ function: Check parameter from command line input : NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "U:P:h", ["help"]) except Exception as e: usage() exitWithRetCode(1, ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): exitWithRetCode(1, ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_user global g_newPath for (key, value) in opts: if (key == "--help" or key == "-h"): usage() exitWithRetCode(0) elif (key == "-U"): g_user = value elif (key == "-P"): g_newPath = value else: exitWithRetCode(1, ErrorCode.GAUSS_500["GAUSS_50000"] % key) Parameter.checkParaVaild(key, value) if (g_user == ""): exitWithRetCode(1, ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".") if (g_newPath == ""): exitWithRetCode(1, ErrorCode.GAUSS_500["GAUSS_50001"] % 'P' + ".") if (not os.path.isabs(g_newPath)): exitWithRetCode(1, ErrorCode.GAUSS_502["GAUSS_50213"] % g_newPath) g_newPath = os.path.normpath(g_newPath)
def parseCommandLine(): """ function: parse input parameters input : NA output: NA """ try: # option '-M' specify the environment parameter GAUSSLOG # option '-P' specify the environment parameter PGHOST|GAUSSTMP # option '-u' install new binary for upgrade opts, args = getopt.getopt(sys.argv[1:], "t:U:X:R:M:P:i:l:c:f:Tu", ["alarm=", "dws-mode", "time_out=", "product=", "licensemode="]) except getopt.GetoptError as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if len(args) > 0: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_opts g_opts = CmdOptions() parameter_map = {"-X": g_opts.clusterConfig, "-R": g_opts.installPath, "-l": g_opts.logFile, "-c": g_opts.clusterName, "-M": g_opts.logPath, "-P": g_opts.tmpPath, "-f": g_opts.static_config_file, "--alarm": g_opts.alarmComponent, "--licensemode": g_opts.licenseMode, "--time_out": g_opts.time_out} parameter_keys = parameter_map.keys() for key, value in opts: if key == "-U": strTemp = value strList = strTemp.split(":") if len(strList) != 2: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] % "U") if strList[0] == "" or strList[1] == "": GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] % "U") g_opts.user = strList[0] g_opts.group = strList[1] elif key in parameter_keys: parameter_map[key] = value elif key == "-t": g_opts.action = value elif key == "--dws-mode": g_opts.dws_mode = True elif key == "-u": g_opts.upgrade = True elif key == "-T": g_opts.installflag = True else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % value) Parameter.checkParaVaild(key, value) g_opts.clusterConfig = parameter_map["-X"] g_opts.installPath = parameter_map["-R"] g_opts.logFile = parameter_map["-l"] g_opts.clusterName = parameter_map["-c"] g_opts.logPath = parameter_map["-M"] g_opts.tmpPath = parameter_map["-P"] g_opts.static_config_file = parameter_map["-f"] g_opts.alarmComponent = parameter_map["--alarm"] g_opts.licenseMode = parameter_map["--licensemode"] g_opts.time_out = parameter_map["--time_out"]
def main(): """ function: main function: 1.parse parameter 2.check $GAUSS_ENV input : NA output: NA """ try: (opts, args) = getopt.getopt(sys.argv[1:], "U:h:t:", ["help"]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) DBUser = "" checkInstall = "preinstall" for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): DBUser = value elif (key == "-t"): checkInstall = value else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % key) # check para vaild Parameter.checkParaVaild(key, value) # check user if (DBUser == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'U' + ".") try: execUser = pwd.getpwuid(os.getuid()).pw_name if (execUser != DBUser): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50004"] % "U") # Check if user exists and if is the right user DefaultValue.checkUser(DBUser, False) except Exception as e: GaussLog.exitWithError(str(e)) # check if have done preinstall for this user cmd = "echo $GAUSS_ENV 2>/dev/null" (status, output) = subprocess.getstatusoutput(cmd) if (status != 0): GaussLog.exitWithError(ErrorCode.GAUSS_518["GAUSS_51802"] % "GAUSS_ENV") if checkInstall == "preinstall": if (output.strip() == PREINSTALL_FLAG or output.strip() == INSTALL_FLAG): GaussLog.printMessage("Successfully checked GAUSS_ENV.") sys.exit(0) else: GaussLog.exitWithError(ErrorCode.GAUSS_518["GAUSS_51805"] % "GAUSS_ENV") elif checkInstall == "install" and output.strip() == INSTALL_FLAG: GaussLog.exitWithError(ErrorCode.GAUSS_518["GAUSS_51806"])
def main(): """ main function """ try: (opts, args) = getopt.getopt(sys.argv[1:], "p:S:f:s:d:h", ["help"]) except Exception as e: usage() GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) port = "" sqlfile = "" outputfile = "" database = "" for (key, value) in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-p"): port = value elif (key == "-S"): sqlfile = value elif (key == "-f"): outputfile = value elif (key == "-s"): snapid = value elif (key == "-d"): database = value else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % key) Parameter.checkParaVaild(key, value) # check parameter if (port == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'p' + ".") if (sqlfile == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'S' + ".") if (outputfile == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'f' + ".") if (database == ""): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'd' + ".") try: output = {} exesql = "" if os.path.exists(sqlfile): with open(sqlfile, "r") as fp: lines = fp.readlines() for line in lines: exesql += line + "\n" (status, result, err_output) = \ ClusterCommand.excuteSqlOnLocalhost(port, exesql, database) cmd = "rm -rf %s" % sqlfile if (err_output != ""): output["status"] = status output["error_output"] = err_output GaussLog.exitWithError(ErrorCode.GAUSS_513["GAUSS_51300"] % exesql + "Errors:%s" % err_output) output["status"] = status output["result"] = result output["error_output"] = err_output g_file.createFileInSafeMode(outputfile) with open(outputfile, "w") as fp_json: json.dump(output, fp_json) (status, outpout) = subprocess.getstatusoutput(cmd) if status != 0: raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd + "Error:\n%s" % output) except Exception as e: GaussLog.exitWithError("Errors:%s" % str(e))
def main(): """ function: main function input : NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "U:P:l:pbhifs:", [ "position=", "parameter", "binary_file", "logpath=", "help", "ingore_miss", "force", "static_file=" ]) except getopt.GetoptError as e: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % e.msg) if (len(args) > 0): GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_clusterUser global g_ignoreMiss global g_staticFile global g_forceRestore restoreDir = "" restorePara = False restoreBin = False logFile = "" for key, value in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_clusterUser = value.strip() elif (key == "-P" or key == "--position"): restoreDir = value.strip() elif (key == "-p" or key == "--parameter"): restorePara = True elif (key == "-b" or key == "--binary_file"): restoreBin = True elif (key == "-i" or key == "--ingore_miss"): g_ignoreMiss = True elif (key == "-s" or key == "--static_file"): g_staticFile = value.strip() elif (key == "-l" or key == "--logpath"): logFile = value elif (key == "-f" or key == "--force"): g_forceRestore = True else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % value) Parameter.checkParaVaild(key, value) if (g_ignoreMiss): gaussHome = DefaultValue.getEnv("GAUSSHOME") if not gaussHome: return # check if user exist and is the right user checkUserExist() # check log file checkLogFile(logFile) # check -p and -b checkRestorePara(restorePara, restoreBin) # check -P checkRestoreDir(restoreDir) try: LocalRestorer = LocalRestore(logFile, g_clusterUser, restoreDir, restorePara, restoreBin) LocalRestorer.run() except Exception as e: GaussLog.exitWithError(str(e))
def main(): """ function: main function 1.parse command line 2.check if user exist and is the right user 3.check log file 4.check backupPara and backupBin 5.check tmpBackupDir 6.do backup input : NA output: NA """ try: opts, args = getopt.getopt(sys.argv[1:], "U:P:B:l:pbhi", ["position=", "backupdir=", \ "nodeName=", "parameter", "binary_file", "logpath=", "help", "ingore_miss"]) except getopt.GetoptError as e: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e)) if (len(args) > 0): GaussLog.exitWithError( ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0])) global g_clusterUser global g_ignoreMiss tmpBackupDir = "" backupDir = "" backupPara = False backupBin = False logFile = "" nodeName = "" for key, value in opts: if (key == "-h" or key == "--help"): usage() sys.exit(0) elif (key == "-U"): g_clusterUser = value.strip() elif (key == "-P" or key == "--position"): tmpBackupDir = value.strip() elif (key == "-B" or key == "--backupdir"): backupDir = value.strip() elif (key == "-p" or key == "--parameter"): backupPara = True elif (key == "-b" or key == "--binary_file"): backupBin = True elif (key == "-i" or key == "--ingore_miss"): g_ignoreMiss = True elif (key == "-l" or key == "--logpath"): logFile = value.strip() elif (key == "--nodeName"): nodeName = value.strip() else: GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % value) Parameter.checkParaVaild(key, value) if (g_ignoreMiss): gaussHome = DefaultValue.getEnv("GAUSSHOME") if not gaussHome: return # check if user exist and is the right user checkUserParameter() DefaultValue.checkUser(g_clusterUser, False) # check log file checkLogFile(logFile) # check backupPara and backupBin checkBackupPara(backupPara, backupBin) # check tmpBackupDir checkTmpBackupDir(tmpBackupDir) try: LocalBackuper = LocalBackup(logFile, g_clusterUser, tmpBackupDir, backupDir, backupPara, backupBin, nodeName) LocalBackuper.run() except Exception as e: GaussLog.exitWithError(str(e))