当前位置: 首页>>代码示例>>Python>>正文


Python Terminator.terminate_backend_dbs方法代码示例

本文整理汇总了Python中terminator.Terminator.terminate_backend_dbs方法的典型用法代码示例。如果您正苦于以下问题:Python Terminator.terminate_backend_dbs方法的具体用法?Python Terminator.terminate_backend_dbs怎么用?Python Terminator.terminate_backend_dbs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在terminator.Terminator的用法示例。


在下文中一共展示了Terminator.terminate_backend_dbs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_replicator

# 需要导入模块: from terminator import Terminator [as 别名]
# 或者: from terminator.Terminator import terminate_backend_dbs [as 别名]
    def setup_replicator(self):
        '''
        Target:
            - clone a database in PostgreSQL.
        '''
        connecter = self.get_connecter()
        self.logger.debug(Messenger.BEGINNING_EXE_REPLICATOR)
        replicator = self.get_replicator(connecter)

        pg_superuser = connecter.is_pg_superuser()
        if not pg_superuser:
            connecter.cursor.execute(Queries.GET_PG_DB_SOME_DATA,
                                     (replicator.original_dbname, ))
            db = connecter.cursor.fetchone()
            if db['owner'] != connecter.user:
                self.logger.stop_exe(Messenger.ACTION_DB_NO_SUPERUSER)

        # Terminate every connection to the database which is going to be
        # replicated, if necessary
        if self.args.terminate:
            terminator = Terminator(connecter,
                                    target_dbs=[replicator.original_dbname],
                                    logger=self.logger)
            terminator.terminate_backend_dbs([replicator.original_dbname])

        # Clone the database
        replicator.replicate_pg_db()

        # Close connection to PostgreSQL
        connecter.pg_disconnect()
开发者ID:alejandrosantana,项目名称:py_pg_tools,代码行数:32,代码来源:orchestrator.py

示例2: setup_dropper

# 需要导入模块: from terminator import Terminator [as 别名]
# 或者: from terminator.Terminator import terminate_backend_dbs [as 别名]
    def setup_dropper(self):
        '''
        Target:
            - delete specified databases in PostgreSQL.
        '''
        connecter = self.get_connecter()
        self.logger.debug(Messenger.BEGINNING_EXE_DROPPER)
        dropper = self.get_dropper(connecter)

        # Terminate every connection to the target databases if necessary
        if self.args.terminate:
            terminator = Terminator(connecter, target_dbs=dropper.dbnames,
                                    logger=self.logger)
            terminator.terminate_backend_dbs(dropper.dbnames)

        # Delete the databases
        dropper.drop_pg_dbs(dropper.dbnames)

        # Close connection to PostgreSQL
        connecter.pg_disconnect()
开发者ID:alejandrosantana,项目名称:py_pg_tools,代码行数:22,代码来源:orchestrator.py

示例3: setup_vacuumer

# 需要导入模块: from terminator import Terminator [as 别名]
# 或者: from terminator.Terminator import terminate_backend_dbs [as 别名]
    def setup_vacuumer(self):
        '''
        Target:
            - executes the vacuumer taking into account the value of its
              variables.
        '''
        connecter = self.get_connecter()
        self.logger.debug(Messenger.BEGINNING_EXE_VACUUMER)
        vacuumer = self.get_vacuumer(connecter)

        # Check if the role of user connected to PostgreSQL is superuser
        pg_superuser = connecter.is_pg_superuser()
        if not pg_superuser:
            # Users who are not superusers will only be able to vacuum the
            # databases they own
            vacuumer.db_owner = connecter.user
            self.logger.warning(Messenger.ACTION_DB_NO_SUPERUSER)

        # Get PostgreSQL databases' names, connection permissions and owners
        dbs_all = connecter.get_pg_dbs_data(vacuumer.ex_templates,
                                            vacuumer.db_owner)

        # Show and log their names
        Orchestrator.show_dbs(dbs_all, self.logger)

        # Get the target databases in a list
        vacuum_list = DbSelector.get_filtered_dbs(
            dbs_all, vacuumer.in_dbs, vacuumer.ex_dbs, vacuumer.in_regex,
            vacuumer.ex_regex, vacuumer.in_priority, self.logger)

        # Terminate every connection to these target databases if necessary
        if self.args.terminate:
            terminator = Terminator(connecter, target_dbs=vacuum_list,
                                    logger=self.logger)
            terminator.terminate_backend_dbs(vacuum_list)

        # Vacuum the target databases
        vacuumer.vacuum_dbs(vacuum_list)

        # Close connection to PostgreSQL
        connecter.pg_disconnect()
开发者ID:alejandrosantana,项目名称:py_pg_tools,代码行数:43,代码来源:orchestrator.py

示例4: setup_alterer

# 需要导入模块: from terminator import Terminator [as 别名]
# 或者: from terminator.Terminator import terminate_backend_dbs [as 别名]
    def setup_alterer(self):
        '''
        Target:
            - change the owner of the specified databases in PostgreSQL.
        '''
        connecter = self.get_connecter()
        self.logger.debug(Messenger.BEGINNING_EXE_ALTERER)
        alterer = self.get_alterer(connecter)

        # Check if the role of user connected to PostgreSQL is superuser
        pg_superuser = connecter.is_pg_superuser()
        if not pg_superuser:
            # Users who are not superusers will only be able to backup the
            # databases they own
            owner = connecter.user
            self.logger.highlight('warning', Messenger.ACTION_DB_NO_SUPERUSER,
                                  'yellow', effect='bold')
        else:
            owner = ''

        # Get PostgreSQL databases' names, connection permissions and owners
        dbs_all = connecter.get_pg_dbs_data(ex_templates=False, db_owner=owner)
        # Show and log their names
        Orchestrator.show_dbs(dbs_all, self.logger)

        # Get the target databases in a list
        alt_list = DbSelector.get_filtered_dbs(
            dbs_all=dbs_all, in_dbs=alterer.in_dbs, logger=self.logger)

        # Terminate every connection to the target databases if necessary
        if self.args.terminate:
            terminator = Terminator(connecter, target_dbs=alt_list,
                                    logger=self.logger)
            terminator.terminate_backend_dbs(alt_list)

        # Delete the databases
        alterer.alter_dbs_owner(alt_list)

        # Close connection to PostgreSQL
        connecter.pg_disconnect()
开发者ID:alejandrosantana,项目名称:py_pg_tools,代码行数:42,代码来源:orchestrator.py

示例5: setup_backer

# 需要导入模块: from terminator import Terminator [as 别名]
# 或者: from terminator.Terminator import terminate_backend_dbs [as 别名]
    def setup_backer(self):
        '''
        Target:
            - executes the backer depending on the type of backup to make, the
              role of the user who is connected to PostgreSQL and the rest of
              the conditions. It calls a terminator if necessary.
        '''
        connecter = self.get_connecter()

        # Get databases or clusters' backer depending on the option selected
        # by the user in console
        if self.args.cluster:
            self.logger.debug(Messenger.BEGINNING_EXE_CL_BACKER)
            backer = self.get_cl_backer(connecter)
        else:
            self.logger.debug(Messenger.BEGINNING_EXE_DB_BACKER)
            backer = self.get_db_backer(connecter)

        # If necessary, add group and bkp_path to the mailer to be sent within
        # the process information
        if self.args.config_mailer:
            self.logger.mailer.add_group(backer.group)
            path = backer.bkp_path + backer.group
            self.logger.mailer.add_bkp_path(path)

        # Check if the role of user connected to PostgreSQL is superuser
        pg_superuser = connecter.is_pg_superuser()
        if not pg_superuser:
            if self.args.cluster is False:
                # Users who are not superusers will only be able to backup the
                # databases they own
                backer.db_owner = connecter.user
                self.logger.highlight(
                    'warning', Messenger.ACTION_DB_NO_SUPERUSER,
                    'yellow', effect='bold')
            else:  # Backup the cluster can only be made by superuser
                self.logger.stop_exe(Messenger.ACTION_CL_NO_SUPERUSER)

        # Make the backups
        if self.args.cluster is False:  # Backup databases

            # Get PostgreSQL databases' names, connection permissions and
            # owners
            dbs_all = connecter.get_pg_dbs_data(backer.ex_templates,
                                                backer.db_owner)
            # Show and log their names
            Orchestrator.show_dbs(dbs_all, self.logger)

            # Get the target databases in a list
            bkp_list = DbSelector.get_filtered_dbs(
                dbs_all, backer.in_dbs, backer.ex_dbs, backer.in_regex,
                backer.ex_regex, backer.in_priority, self.logger)

            # Terminate every connection to these target databases if necessary
            if self.args.terminate:
                terminator = Terminator(connecter, target_dbs=bkp_list,
                                        logger=self.logger)
                terminator.terminate_backend_dbs(bkp_list)

            backer.backup_dbs(bkp_list)  # Make databases' backup

        else:  # Backup a cluster
            # Terminate every connection to any database of the cluster if
            # necessary
            if self.args.terminate:
                terminator = Terminator(connecter, target_all=True,
                                        logger=self.logger)
                terminator.terminate_backend_all()

            backer.backup_cl()  # Make cluster's backup

        # Close connection to PostgreSQL
        connecter.pg_disconnect()
开发者ID:alejandrosantana,项目名称:py_pg_tools,代码行数:75,代码来源:orchestrator.py


注:本文中的terminator.Terminator.terminate_backend_dbs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。