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 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))