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


Python Terminator.terminate_backend_all方法代码示例

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


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

示例1: setup_backer

# 需要导入模块: from terminator import Terminator [as 别名]
# 或者: from terminator.Terminator import terminate_backend_all [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_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。