コード例 #1
0
ファイル: DN_OLAP.py プロジェクト: Pengn117/openGauss-server
 def copyAndModCertFiles(self):
     """
     function : copy and chage permission cert files
     input : NA
     output : NA
     """
     user = g_OSlib.getUserInfo()["name"]
     appPath = DefaultValue.getInstallDir(user)
     caPath = os.path.join(appPath, "share/sslcert/om")
     # cp cert files
     g_file.cpFile("%s/server.crt" % caPath, "%s/" % self.instInfo.datadir)
     g_file.cpFile("%s/server.key" % caPath, "%s/" % self.instInfo.datadir)
     g_file.cpFile("%s/cacert.pem" % caPath, "%s/" % self.instInfo.datadir)
     g_file.cpFile("%s/server.key.cipher" % caPath,
                   "%s/" % self.instInfo.datadir)
     g_file.cpFile("%s/server.key.rand" % caPath,
                   "%s/" % self.instInfo.datadir)
     # change mode
     g_file.changeMode(DefaultValue.KEY_FILE_MODE,
                       "%s/server.crt" % self.instInfo.datadir)
     g_file.changeMode(DefaultValue.KEY_FILE_MODE,
                       "%s/server.key" % self.instInfo.datadir)
     g_file.changeMode(DefaultValue.KEY_FILE_MODE,
                       "%s/cacert.pem" % self.instInfo.datadir)
     g_file.changeMode(DefaultValue.KEY_FILE_MODE,
                       "%s/server.key.cipher" % self.instInfo.datadir)
     g_file.changeMode(DefaultValue.KEY_FILE_MODE,
                       "%s/server.key.rand" % self.instInfo.datadir)
コード例 #2
0
    def __decompressBinPackage(self):
        """
        function: Install database binary file.
        input : NA
        output: NA
        """
        if self.dws_mode:
            self.logger.log("Copying bin file.")
            bin_image_path = DefaultValue.DWS_APP_PAHT
            srcPath = "'%s'/*" % bin_image_path
            destPath = "'%s'/" % self.installPath
            cmd = g_file.SHELL_CMD_DICT["copyFile"] % (srcPath, destPath)
            self.logger.debug("Copy command: " + cmd)
            status, output = subprocess.getstatusoutput(cmd)
            if status != 0:
                self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50214"] %
                                    srcPath + " Error: " + output)
        else:
            self.logger.log("Decompressing bin file.")
            tarFile = g_OSlib.getBz2FilePath()
            # let bin executable
            g_file.changeMode(DefaultValue.KEY_DIRECTORY_MODE, tarFile)

            cmd = "export LD_LIBRARY_PATH=$GPHOME/script/gspylib/clib:" \
                  "$LD_LIBRARY_PATH && "
            # decompress tar file.
            strCmd = cmd + "tar -xpf \"" + tarFile + "\" -C \"" + \
                     self.installPath + "\""
            self.logger.log("Decompress command: " + strCmd)
            status, output = subprocess.getstatusoutput(strCmd)
            if status != 0:
                self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50217"] %
                                    tarFile + " Error: \n%s" % str(output))

            # mv $GPHOME/script/transfer.py to $GAUSSHOME/bin/
            dirName = os.path.dirname(os.path.realpath(__file__))
            transferFile = dirName + "/../../script/transfer.py"
            if os.path.exists(transferFile):
                g_file.cpFile(transferFile, self.installPath + "/bin/")
                g_file.removeFile(transferFile)
            # cp $GPHOME/script to $GAUSSHOME/bin/
            g_file.cpFile(dirName + "/../../script",
                          self.installPath + "/bin/")

            # cp $GAUSSHOME/bin/script/gspylib/etc/sql/pmk to /share/postgresql
            destPath = self.installPath + "/share/postgresql/"
            pmkPath = self.installPath + "/bin/script/gspylib/etc/sql/"
            pmkFile = pmkPath + "pmk_schema.sql"
            if os.path.exists(pmkFile):
                g_file.cpFile(pmkFile, destPath)

            pmkSingeInstFile = pmkPath + "pmk_schema_single_inst.sql"
            if os.path.exists(pmkSingeInstFile):
                g_file.cpFile(pmkSingeInstFile, destPath)

            # change owner for tar file.
            g_file.changeOwner(self.user, self.installPath, True)
        self.logger.log("Successfully decompressed bin file.")
コード例 #3
0
 def __bakInstallPackage(self):
     """
     function: backup install package for replace
     input : NA
     output: NA
     """
     dirName = os.path.dirname(os.path.realpath(__file__))
     packageFile = "%s/%s" % (os.path.join(dirName, "./../../"),
                              DefaultValue.get_package_back_name())
     # Check if MPPDB package exist
     if not os.path.exists(packageFile):
         self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50201"]
                             % 'MPPDB package' + " Can not back up.")
     # Save MPPDB package to bin path
     destPath = "'%s'/bin/" % self.installPath
     g_file.cpFile(packageFile, destPath)
コード例 #4
0
    def __distributeBackupFile(self, tmp_backupDir, flag):
        """
        function: distribute Backup File
        input : tmp_backupDir, flag
        output: NA
        """
        # compresses the configuration files for all node backups
        tarFiles = "%s_*.tar" % flag
        tarName = "%s.tar" % flag
        cmd = g_file.SHELL_CMD_DICT["compressTarFile"] \
              % (tmp_backupDir, tarName,
                 tarFiles, DefaultValue.KEY_FILE_MODE, tarName)
        if (flag == "parameter"):
            (status, output) = subprocess.getstatusoutput(cmd)
            if (status != 0):
                raise Exception(
                    ErrorCode.GAUSS_514["GAUSS_51400"]
                    % cmd + " Error:\n%s" % output)
        else:
            self._runCmd(cmd)

        # prepares the backup directory for the specified node
        cmd = g_file.SHELL_CMD_DICT["createDir"] \
              % (self.context.backupDir, self.context.backupDir,
                 DefaultValue.KEY_DIRECTORY_MODE)
        self._runCmd(cmd, self.context.nodename)
        # send backup package to the specified node from the local node
        originalFile = "'%s'/%s.tar" % (tmp_backupDir, flag)
        if flag == "parameter":
            if self.context.nodename != [g_OSlib.getHostName()]:
                self.context.sshTool.scpFiles(
                    originalFile,
                    self.context.backupDir, self.context.nodename)
            else:
                g_file.cpFile(originalFile, self.context.backupDir)
        else:
            targetFile = "'%s'/%s.tar" % (self.context.backupDir, flag)
            cmd = g_file.SHELL_CMD_DICT["copyFile"] % (
                originalFile, targetFile)
            self._runCmd(cmd)
コード例 #5
0
    def distributeDNCert(self, certList, dnDict=None):
        """
        function: distribute ssl cert files on single_inst cluster
        input: certList:     cert files list
               dnDict:       dictionary
        output: NA
        """
        tempDir = "tempCertDir"
        gphost = DefaultValue.getTmpDirFromEnv()
        if dnDict is None:
            dnDict = {}
        dnName = dnDict.keys()
        certPathList = []
        self.logger.debug(certList)

        for num in iter(certList):
            sslPath = os.path.join(os.path.join(gphost, tempDir), num)
            certPathList.append(sslPath)
        # local mode
        if self.context.g_opts.localMode:
            localDnDir = dnDict[DefaultValue.GetHostIpOrName()]
            for num in range(len(certList)):
                # distribute gsql SSL cert
                if (os.path.isfile(os.path.join(localDnDir, certList[num]))):
                    os.remove(os.path.join(localDnDir, certList[num]))
                if (os.path.isfile(certPathList[num])):
                    g_file.cpFile(certPathList[num],
                                  os.path.join(localDnDir, certList[num]))
                    g_file.changeMode(DefaultValue.KEY_FILE_MODE,
                                      os.path.join(localDnDir, certList[num]))

                    # remove 'sslcrl-file.crl' file
            if (DefaultValue.SSL_CRL_FILE not in certList and os.path.isfile(
                    os.path.join(localDnDir, DefaultValue.SSL_CRL_FILE))):
                os.remove(os.path.join(localDnDir, DefaultValue.SSL_CRL_FILE))

                # config 'sslcrl-file.crl' option in 'postgresql.conf'
            if (os.path.isfile(
                    os.path.join(localDnDir, DefaultValue.SSL_CRL_FILE))):
                cmd = "gs_guc set " \
                      "-D %s -c \"ssl_crl_file=\'%s\'\"" % \
                      (localDnDir, DefaultValue.SSL_CRL_FILE)
                (status, output) = subprocess.getstatusoutput(cmd)
                if (status != 0):
                    raise Exception((ErrorCode.GAUSS_514["GAUSS_51400"] %
                                     cmd) +
                                    "Failed set 'ssl_crl_file' option." +
                                    "Error: \n%s" % output)
            else:
                cmd = "gs_guc set -D %s -c \"ssl_crl_file=\'\'\"" \
                      % localDnDir
                (status, output) = subprocess.getstatusoutput(cmd)
                if (status != 0):
                    raise Exception((ErrorCode.GAUSS_514["GAUSS_51400"] %
                                     cmd) +
                                    "Failed set 'ssl_crl_file' option." +
                                    "Error: \n%s" % output)
                    # remove backup flag file 'certFlag'
            if (os.path.isfile(os.path.join(localDnDir, 'certFlag'))):
                os.remove(os.path.join(localDnDir, 'certFlag'))
            self.logger.log(
                "Replace SSL cert files with local mode successfully.")
            return
        # not local mode
        for node in dnName:
            for num in range(len(certList)):
                sshcmd = g_file.SHELL_CMD_DICT["deleteFile"] % (os.path.join(
                    dnDict[node],
                    certList[num]), os.path.join(dnDict[node], certList[num]))
                self.sshTool.executeCommand(sshcmd,
                                            "Delete read only cert file.",
                                            DefaultValue.SUCCESS, [node],
                                            self.context.g_opts.mpprcFile)

                if (os.path.exists(certPathList[num])):
                    self.sshTool.scpFiles(certPathList[num], dnDict[node],
                                          [node])

                # change permission of cert file 600,
                # there no need to is exists file,
                # because the files must be exist.
                sshcmd = g_file.SHELL_CMD_DICT["changeMode"] % (
                    DefaultValue.KEY_FILE_MODE,
                    os.path.join(dnDict[node], certList[num]))
                self.sshTool.executeCommand(sshcmd,
                                            "Change file permisstion.'",
                                            DefaultValue.SUCCESS, [node],
                                            self.context.g_opts.mpprcFile)

            if (DefaultValue.SSL_CRL_FILE in certList):
                if (node == DefaultValue.GetHostIpOrName()):
                    sshcmd = "gs_guc set " \
                             "-D %s -c \"ssl_crl_file='%s'\"" \
                             % (dnDict[node], DefaultValue.SSL_CRL_FILE)
                else:
                    sshcmd = "gs_guc set " \
                             " -D %s -c \"ssl_crl_file=\\\\\\'%s\\\\\\'\"" \
                             % (dnDict[node], DefaultValue.SSL_CRL_FILE)
                self.sshTool.executeCommand(sshcmd, "Find 'ssl_crl_file'",
                                            DefaultValue.SUCCESS, [node],
                                            self.context.g_opts.mpprcFile)
            else:
                # no ssl cert file there will delete old cert file,
                # and config option ssl_crl_file = ''
                sshcmd = g_file.SHELL_CMD_DICT["deleteFile"] % (
                    os.path.join(dnDict[node], DefaultValue.SSL_CRL_FILE),
                    os.path.join(dnDict[node], DefaultValue.SSL_CRL_FILE))
                self.sshTool.executeCommand(sshcmd, "Find 'ssl_crl_file'",
                                            DefaultValue.SUCCESS, [node],
                                            self.context.g_opts.mpprcFile)
                if (node == DefaultValue.GetHostIpOrName()):
                    sshcmd = "gs_guc set " \
                             "-D %s -c \"ssl_crl_file=\'\'\"" % (dnDict[node])
                else:
                    sshcmd = \
                        "gs_guc set " \
                        "-D %s " \
                        "-c \"ssl_crl_file=\\\\\\'\\\\\\'\"" % (dnDict[node])
                self.sshTool.executeCommand(sshcmd, "Find 'ssl_crl_file'",
                                            DefaultValue.SUCCESS, [node],
                                            self.context.g_opts.mpprcFile)
                # remove file 'sslcrl-file.crl'
                sshcmd = g_file.SHELL_CMD_DICT["deleteFile"] % (
                    os.path.join(dnDict[node], DefaultValue.SSL_CRL_FILE),
                    os.path.join(dnDict[node], DefaultValue.SSL_CRL_FILE))
                self.sshTool.executeCommand(sshcmd,
                                            "Delete read only cert file.",
                                            DefaultValue.SUCCESS, [node],
                                            self.context.g_opts.mpprcFile)
            # remove backup flag file 'certFlag'
            sshcmd = g_file.SHELL_CMD_DICT["deleteFile"] % (os.path.join(
                dnDict[node],
                "certFlag"), os.path.join(dnDict[node], "certFlag"))
            self.sshTool.executeCommand(sshcmd, "Delete backup flag file.",
                                        DefaultValue.SUCCESS, [node],
                                        self.context.g_opts.mpprcFile)
            self.logger.log("%s replace SSL cert files successfully." % node)
コード例 #6
0
    def installToolsPhase1(self):
        """
        function: install tools to local machine
        input: NA
        output: NA
        """
        self.context.logger.log("Installing the tools on the local node.",
                                "addStep")
        try:
            # Determine if the old version of the distribution package
            # is in the current directory
            oldPackName = "%s-Package-bak.tar.gz" \
                          % VersionInfo.PRODUCT_NAME_PACKAGE
            oldPackPath = os.path.join(self.context.clusterToolPath,
                                       oldPackName)
            if os.path.exists(self.context.clusterToolPath):
                versionFile = os.path.join(self.context.clusterToolPath,
                                           "version.cfg")
                if os.path.isfile(versionFile):
                    version, number, commitid = VersionInfo.get_version_info(
                        versionFile)
                    newPackName = "%s-Package-bak_%s.tar.gz" % (
                        VersionInfo.PRODUCT_NAME_PACKAGE, commitid)
                    newPackPath = os.path.join(self.context.clusterToolPath,
                                               newPackName)
                    if os.path.isfile(oldPackPath):
                        cmd = "(if [ -f '%s' ];then mv -f '%s' '%s';fi)" % (
                            oldPackPath, oldPackPath, newPackPath)
                        self.context.logger.debug(
                            "Command for rename bak-package: %s." % cmd)
                        DefaultValue.execCommandWithMode(
                            cmd, "backup bak-package files",
                            self.context.sshTool, self.context.localMode
                            or self.context.isSingle, self.context.mpprcFile)

            if (self.context.mpprcFile != ""):
                # check mpprc file
                self.checkMpprcFile()
            # check the package is not matches the system
            DefaultValue.checkPackageOS()
            # get the package path
            dirName = os.path.dirname(os.path.realpath(__file__))
            packageDir = os.path.join(dirName, "./../../../../")
            packageDir = os.path.normpath(packageDir)

            # change logPath owner
            self.context.logger.debug("Modifying logPath owner")
            dirName = os.path.dirname(self.context.logFile)
            topDirFile = "%s/topDirPath.dat" % dirName
            keylist = []
            if (self.context.localMode):
                if (os.path.exists(topDirFile)):
                    keylist = g_file.readFile(topDirFile)
                    if (keylist != []):
                        for key in keylist:
                            if (os.path.exists(key.strip())):
                                g_file.changeOwner(self.context.user,
                                                   key.strip(), True, "shell")
                            else:
                                self.context.logger.debug(
                                    "Warning: Can not find the "
                                    "path in topDirPath.dat.")

                    g_file.removeFile(topDirFile)
            self.context.logger.debug("Successfully modified logPath owner")

            # Delete the old bak package in GPHOME before copy the new one.
            for bakPack in DefaultValue.PACKAGE_BACK_LIST:
                bakFile = os.path.join(self.context.clusterToolPath, bakPack)
                if (os.path.isfile(bakFile)):
                    self.context.logger.debug("Remove old bak-package: %s." %
                                              bakFile)
                    g_file.removeFile(bakFile)

            DefaultValue.makeCompressedToolPackage(packageDir)

            # check and create tool package dir
            global toolTopPath
            ownerPath = self.context.clusterToolPath
            clusterToolPathExistAlready = True
            # if clusterToolPath exist,
            # set the clusterToolPathExistAlready False
            if (not os.path.exists(ownerPath)):
                clusterToolPathExistAlready = False
                ownerPath = DefaultValue.getTopPathNotExist(ownerPath)
                toolTopPath = ownerPath
            # append clusterToolPath to self.context.needFixOwnerPaths
            # self.context.needFixOwnerPaths will be checked the ownet
            self.context.needFixOwnerPaths.append(ownerPath)

            # if clusterToolPath is not exist, then create it

            if not os.path.exists(self.context.clusterToolPath):
                g_file.createDirectory(self.context.clusterToolPath)
                g_file.changeMode(DefaultValue.MAX_DIRECTORY_MODE,
                                  self.context.clusterToolPath, True, "shell")

            # change the clusterToolPath permission
            if not clusterToolPathExistAlready:
                #check the localMode
                if self.context.localMode:
                    #local mode,change the owner
                    g_file.changeMode(DefaultValue.DIRECTORY_MODE,
                                      ownerPath,
                                      recursive=True,
                                      cmdType="shell")
                    g_file.changeOwner(self.context.user,
                                       ownerPath,
                                       recursive=True,
                                       cmdType="shell")
                #not localMode, only change the permission
                else:
                    g_file.changeMode(DefaultValue.MAX_DIRECTORY_MODE,
                                      ownerPath,
                                      recursive=True,
                                      cmdType="shell")
            else:
                g_file.changeMode(DefaultValue.DIRECTORY_MODE,
                                  ownerPath,
                                  recursive=False,
                                  cmdType="shell")

            # Send compressed package to local host
            if (packageDir != self.context.clusterToolPath):
                # copy the package to clusterToolPath
                g_file.cpFile(
                    os.path.join(packageDir,
                                 DefaultValue.get_package_back_name()),
                    self.context.clusterToolPath)

            # Decompress package on local host
            g_file.decompressFiles(
                os.path.join(self.context.clusterToolPath,
                             DefaultValue.get_package_back_name()),
                self.context.clusterToolPath)

            # change mode of packages
            g_file.changeMode(DefaultValue.DIRECTORY_MODE,
                              self.context.clusterToolPath,
                              recursive=True,
                              cmdType="shell")

            # get the top path of mpprc file need to be created on local node
            # this is used to fix the newly created path owner later
            if self.context.mpprcFile != "":
                ownerPath = self.context.mpprcFile
                if (not os.path.exists(self.context.mpprcFile)):
                    while True:
                        # find the top path to be created
                        (ownerPath, dirName) = os.path.split(ownerPath)
                        if os.path.exists(ownerPath) or dirName == "":
                            ownerPath = os.path.join(ownerPath, dirName)
                            break
                self.context.needFixOwnerPaths.append(ownerPath)

            # check the current storage package path is legal
            Current_Path = os.path.dirname(os.path.realpath(__file__))
            DefaultValue.checkPathVaild(os.path.normpath(Current_Path))
            # set ENV
            cmd = "%s -t %s -u %s -l %s -X '%s' -Q %s" % (
                OMCommand.getLocalScript("Local_PreInstall"),
                ACTION_SET_TOOL_ENV, self.context.user, self.context.localLog,
                self.context.xmlFile, self.context.clusterToolPath)
            if self.context.mpprcFile != "":
                cmd += " -s '%s' " % self.context.mpprcFile
                #check the localmode,if mode is local then modify user group
                if self.context.localMode:
                    cmd += "-g %s" % self.context.group
            (status, output) = subprocess.getstatusoutput(cmd)
            # if cmd failed, then exit
            if status != 0:
                self.context.logger.debug(
                    "Command for setting %s tool environment variables: %s" %
                    (VersionInfo.PRODUCT_NAME, cmd))
                raise Exception(output)

        except Exception as e:
            raise Exception(str(e))

        self.context.logger.log(
            "Successfully installed the tools on the local node.", "constant")
コード例 #7
0
    def doRestore(self):
        """
        function: restore files
                  Restoring binary files:
                  1.decompress tar file
                  2.Check binary files
                  3.Create installation path
                  4.Restore binary files to install path
                  Restoring parameter files:
                  1.decompress tar file
                  2.delete temporary directory
                  3.extract parameter files to the temporary directory
                  4.check hostname and parameter
                  5.Restore parameter files
                  6.Remove the temporary directory
        input : NA
        output: NA
        """
        self.logger.log("Restoring files.")

        if self.restoreBin:
            self.logger.log("Restoring binary files.")
            try:
                # decompress tar file
                self.decompressTarFile("binary")

                # Checking binary files
                self.logger.debug("Checking if binary files exist.")
                tarName = os.path.join(self.restoreDir, self.binTarName)
                if (not os.path.exists(tarName)):
                    raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] %
                                    "Binary files")

                # Creating installation path
                self.logger.debug(
                    "Creating installation path if did not exist.")
                if (not os.path.exists(self.installPath)):
                    os.makedirs(self.installPath,
                                DefaultValue.KEY_DIRECTORY_PERMISSION)

                # Restore binary files to install path.
                self.logger.debug("Restore binary files to install path.")
                g_file.cleanDirectoryContent(self.installPath)
                cmd = g_file.SHELL_CMD_DICT["decompressTarFile"] % (
                    self.restoreDir, tarName)
                cmd += " && "
                cmd += g_file.SHELL_CMD_DICT["copyFile"] % (
                    "'%s'/*" % self.binExtractName, self.installPath)
                self.logger.debug("Command for restoring binary files:%s." %
                                  cmd)
                (status, output) = subprocess.getstatusoutput(cmd)
                if (status != 0):
                    raise Exception(ErrorCode.GAUSS_502["GAUSS_50220"] % (
                                "binary files to install path[%s]" % \
                                self.installPath) + " Error: \n%s" % output)
                g_file.removeDirectory(
                    os.path.join(self.restoreDir, self.binExtractName))
            except Exception as e:
                raise Exception(str(e))
            self.logger.log("Successfully restored binary files.")

        if self.restorePara:
            self.logger.log("Restoring parameter files.")
            # Re-obtaining clusterInfo because the restoreBin succeeded
            if self.dbNodeInfo is None:
                self.clusterInfo.initFromStaticConfig(self.user, g_staticFile)
                hostName = DefaultValue.GetHostIpOrName()
                self.dbNodeInfo = self.clusterInfo.getDbNodeByName(hostName)
                if self.dbNodeInfo is None:
                    self.logger.logExit(ErrorCode.GAUSS_516["GAUSS_51619"] %
                                        hostName)

            # Restoring parameter files.
            try:
                # decompress tar file
                self.decompressTarFile("parameter")
                # delete temporary directory
                self.logger.debug(
                    "Delete temporary directory if it has existed.")
                temp_dir = os.path.join(self.restoreDir,
                                        "parameter_%s" % HOSTNAME)
                if (os.path.exists(temp_dir)):
                    g_file.removeDirectory(temp_dir)

                # extract parameter files to the temporary directory
                self.logger.debug(
                    "Extract parameter files to the temporary directory.")
                tarName = os.path.join(self.restoreDir, self.paraTarName)
                if (not os.path.exists(tarName)):
                    if (g_ignoreMiss):
                        self.logger.error(ErrorCode.GAUSS_502["GAUSS_50201"] %
                                          "parameter files")
                        sys.exit(0)
                    else:
                        raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] %
                                        "parameter files")

                cmd = g_file.SHELL_CMD_DICT["decompressTarFile"] % (
                    self.restoreDir, tarName)
                (status, output) = subprocess.getstatusoutput(cmd)
                if (status != 0):
                    raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd +
                                    " Error: \n%s" % output)

                # check hostname
                self.logger.debug("Checking hostname.")
                self.__checkHostName("%s/%s" %
                                     (temp_dir, self.hostnameFileName))
                # check parameter
                self.logger.debug("Checking parameter files.")
                paraFileList = []
                self.__checkParaFiles(temp_dir, paraFileList)

                self.logger.debug("Restoring parameter files.")
                paraFileNum = len(paraFileList)
                for i in range(paraFileNum):
                    tarFileName, paraFilePath = paraFileList[i].split('|')
                    g_file.cpFile(os.path.join(temp_dir, tarFileName),
                                  paraFilePath)

                self.logger.debug("Remove the temporary directory.")
                g_file.removeDirectory(temp_dir)
            except Exception as e:
                g_file.removeDirectory(temp_dir)
                raise Exception(str(e))
            self.logger.log("Successfully restored parameter files.")

        self.logger.log("Successfully restored files.")
コード例 #8
0
ファイル: Backup.py プロジェクト: zoumingzhe/openGauss-server
    def __collectParaFilesToTempDir(self, inst, temp_dir):
        """
        function: 1.check the instance directory
                  2.get the parameter file of instance
                  3.copy the parameter file to backup directory
        input : inst, temp_dir
        output: NA
        """
        if (not os.path.exists(inst.datadir) or len(
                os.listdir(inst.datadir)) == 0):
            if (g_ignoreMiss):
                self.logger.log(
                    "Data directory (%s) of instance (%s) "
                    "does not exist or is empty." % \
                    (inst.datadir, str(inst)))
                return
            else:
                raise Exception(ErrorCode.GAUSS_502["GAUSS_50228"] % \
                                (("data directory [%s] of instance [%s]")
                                 % (inst.datadir, str(inst))))

        paraFileList = {}
        if (inst.instanceRole == DefaultValue.INSTANCE_ROLE_CMSERVER):
            paraFileList[CM_SERVER_CONF] = os.path.join(inst.datadir,
                                                        CM_SERVER_CONF)
        elif (inst.instanceRole == DefaultValue.INSTANCE_ROLE_CMAGENT):
            paraFileList[CM_AGENT_CONF] = os.path.join(inst.datadir,
                                                       CM_AGENT_CONF)
        elif (inst.instanceRole == DefaultValue.INSTANCE_ROLE_GTM):
            paraFileList[GTM_CONF] = os.path.join(inst.datadir, GTM_CONF)
        elif (inst.instanceRole == DefaultValue.INSTANCE_ROLE_COODINATOR):
            paraFileList[POSTGRESQL_CONF] = os.path.join(inst.datadir,
                                                         POSTGRESQL_CONF)
            paraFileList[POSTGRESQL_HBA_CONF] = os.path.join(
                inst.datadir, POSTGRESQL_HBA_CONF)
        elif (inst.instanceRole == DefaultValue.INSTANCE_ROLE_DATANODE):
            paraFileList[POSTGRESQL_CONF] = os.path.join(
                inst.datadir, POSTGRESQL_CONF)
            paraFileList[POSTGRESQL_HBA_CONF] = os.path.join(
                inst.datadir, POSTGRESQL_HBA_CONF)
        else:
            raise Exception(ErrorCode.GAUSS_512["GAUSS_51204"] % (
                "specified", inst.instanceRole))

        for key in paraFileList:
            if (not os.path.exists(paraFileList[key])):
                self.logger.debug(
                    "The parameter path is: %s." % paraFileList[key])
                if (g_ignoreMiss):
                    self.logger.log(
                        "Parameter file of instance [%s] is not existed." % (
                            str(inst)))
                    return
                else:
                    raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % (
                            'parameter file of instance [%s]' % (
                        str(inst))))

        for key in paraFileList:
            backupFileName = "%d_%s" % (inst.instanceId, key)
            g_file.cpFile(paraFileList[key],
                          os.path.join(temp_dir, backupFileName))