本文整理匯總了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()