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