def rotate(self): """This Method runs the rotation. This method will use the methods from the common library to rotate the binary log. """ # Check required privileges check_privileges(self.server, BINLOG_OP_ROTATE, ["RELOAD", "REPLICATION CLIENT"], BINLOG_OP_ROTATE_DESC, self.verbosity, self._report) active_binlog, binlog_size = get_active_binlog_and_size(self.server) if self.verbosity: self._report("# Active binlog file: '{0}' (size: {1} bytes)'" "".format(active_binlog, binlog_size)) if self.binlog_min_size: rotated = rotate(self.server, self.binlog_min_size, reporter=self._report) else: rotated = rotate(self.server, reporter=self._report) if rotated: new_active_binlog, _ = get_active_binlog_and_size(self.server) if active_binlog == new_active_binlog: raise UtilError("Unable to rotate binlog file.") else: self._report("# The binlog file has been rotated.") if self.verbosity: self._report("# New active binlog file: '{0}'" "".format(new_active_binlog))
def rotate(self): """This Method runs the rotation. This method will use the methods from the common library to rotate the binary log. """ # Check required privileges check_privileges(self.server, BINLOG_OP_ROTATE, ["RELOAD", "REPLICATION CLIENT"], BINLOG_OP_ROTATE_DESC, self.verbosity, self._report) active_binlog, binlog_size = get_active_binlog_and_size(self.server) if self.verbosity: self._report("# Active binlog file: '{0}' (size: {1} bytes)'" "".format(active_binlog, binlog_size)) if self.binlog_min_size: rotated = rotate(self.server, self.binlog_min_size, reporter=self._report) else: rotated = rotate(self.server, reporter=self._report) if rotated: new_active_binlog, _ = get_active_binlog_and_size(self.server) if active_binlog == new_active_binlog: raise UtilError("Unable to rotate binlog file.") else: self._report("# The binlog file has been rotated.") if self.verbosity: self._report("# New active binlog file: '{0}'" "".format(new_active_binlog))
def purge(self): """The purge method for a standalone server. Determines the latest log file to purge, which becomes the target file to purge binary logs to in case no other file is specified. """ # Connect to server self.server = Server({'conn_info': self.server_cnx_val}) self.server.connect() # Check required privileges check_privileges(self.server, BINLOG_OP_PURGE, ["SUPER", "REPLICATION SLAVE"], BINLOG_OP_PURGE_DESC, self.verbosity, self._report) # retrieve active binlog info binlog_file_name, active_binlog_file, index_last_in_use = ( get_binlog_info(self.server, reporter=self._report, server_name="server", verbosity=self.verbosity)) # Verify this server is not a Master. processes = self.server.exec_query("SHOW PROCESSLIST") binlog_dump = False for process in processes: if process[4] == "Binlog Dump": binlog_dump = True break hosts = self.server.exec_query("SHOW SLAVE HOSTS") if binlog_dump or hosts: if hosts and not self.verbosity: msg_v = " For more info use verbose option." else: msg_v = "" if self.verbosity >= 1: for host in hosts: self._report("# WARNING: Slave with id:{0} at {1}:{2} " "is connected to this server." "".format(host[0], host[1], host[2])) raise UtilError("The given server is acting as a master and has " "slaves connected to it. To proceed please use the" " --master option.{0}".format(msg_v)) target_binlog_index = self.get_target_binlog_index(binlog_file_name) self._purge(index_last_in_use, active_binlog_file, binlog_file_name, target_binlog_index)
def _check_privileges_to_move_binlogs(server, options): """Check required privileges to move binary logs from server. This method check if the used user possess the required privileges to relocate binary logs from the server. More specifically, the following privilege is required: RELOAD (to flush the binary logs). An exception is thrown if the user doesn't have enough privileges. server[in] Server instance to check. options[in] Dictionary of options (skip_flush_binlogs, verbosity). """ skip_flush = options['skip_flush_binlogs'] verbosity = options['verbosity'] if not skip_flush: check_privileges(server, BINLOG_OP_MOVE, ['RELOAD'], BINLOG_OP_MOVE_DESC, verbosity)
def _check_privileges_to_move_binlogs(server, options): """Check required privileges to move binary logs from server. This method check if the used user possess the required privileges to relocate binary logs from the server. More specifically, the following privilege is required: RELOAD (to flush the binary logs). An exception is thrown if the user doesn't have enough privileges. server[in] Server instance to check. options[in] Dictionary of options (skip_flush_binlogs, verbosity). """ skip_flush = options['skip_flush_binlogs'] verbosity = options['verbosity'] if not skip_flush: check_privileges(server, BINLOG_OP_MOVE, ['RELOAD'], BINLOG_OP_MOVE_DESC, verbosity)
def purge(self): """The purge method for a standalone server. Determines the latest log file to purge, which becomes the target file to purge binary logs to in case no other file is specified. """ # Connect to server self.server = Server({'conn_info': self.server_cnx_val}) self.server.connect() # Check required privileges check_privileges(self.server, BINLOG_OP_PURGE, ["SUPER", "REPLICATION SLAVE"], BINLOG_OP_PURGE_DESC, self.verbosity, self._report) # retrieve active binlog info binlog_file_name, active_binlog_file, index_last_in_use = ( get_binlog_info(self.server, reporter=self._report, server_name="server", verbosity=self.verbosity) ) # Verify this server is not a Master. processes = self.server.exec_query("SHOW PROCESSLIST") binlog_dump = False for process in processes: if process[4] == "Binlog Dump": binlog_dump = True break hosts = self.server.exec_query("SHOW SLAVE HOSTS") if binlog_dump or hosts: if hosts and not self.verbosity: msg_v = " For more info use verbose option." else: msg_v = "" if self.verbosity >= 1: for host in hosts: self._report("# WARNING: Slave with id:{0} at {1}:{2} " "is connected to this server." "".format(host[0], host[1], host[2])) raise UtilError("The given server is acting as a master and has " "slaves connected to it. To proceed please use the" " --master option.{0}".format(msg_v)) target_binlog_index = self.get_target_binlog_index(binlog_file_name) self._purge(index_last_in_use, active_binlog_file, binlog_file_name, target_binlog_index)
def purge(self): """The Purge Method Determines the latest log file to purge among all the slaves, which becomes the target file to purge binary logs to, in case no other file is specified. """ # Create a topology object to verify the connection between master and # slaves servers. self.topology = Topology(self.master_cnx_val, self.slaves_cnx_val, self.options, skip_conn_err=False) self.master = self.topology.master self.slaves = self.topology.slaves # Check required privileges check_privileges(self.master, BINLOG_OP_PURGE, ["SUPER", "REPLICATION SLAVE"], BINLOG_OP_PURGE_DESC, self.verbosity, self._report) # Get binlog info binlog_file_name, active_binlog_file, active_binlog_index = ( get_binlog_info(self.master, reporter=self._report, server_name="master", verbosity=self.verbosity) ) # Verify this Master has at least one slave. if not self.slaves: errormsg = ( _CAN_NOT_VERIFY_SLAVES_STATUS.format(host=self.master.host, port=self.master.port)) raise UtilError(errormsg) # verify the given slaves are connected to this Master. if self.slaves_cnx_val and self.slaves: for slave in self.slaves: slave['instance'].is_configured_for_master(self.master, verify_state=False, raise_error=True) # IO running verification for --slaves option if not slave['instance'].is_connected(): if self.verbosity: self._report("# Slave '{0}:{1}' IO not running" "".format(slave['host'], slave['port'])) raise UtilError( _CAN_NOT_VERIFY_SLAVE_STATUS.format(host=slave['host'], port=slave['port']) ) target_binlog_index = self.get_target_binlog_index(binlog_file_name) index_last_in_use = determine_purgeable_binlogs( active_binlog_index, self.slaves, reporter=self._report, verbosity=self.verbosity ) self._purge(index_last_in_use, active_binlog_file, binlog_file_name, target_binlog_index, server=self.master, server_is_master=True)
def purge(self): """The Purge Method Determines the latest log file to purge among all the slaves, which becomes the target file to purge binary logs to, in case no other file is specified. """ # Create a topology object to verify the connection between master and # slaves servers. self.topology = Topology(self.master_cnx_val, self.slaves_cnx_val, self.options, skip_conn_err=False) self.master = self.topology.master self.slaves = self.topology.slaves # Check required privileges check_privileges(self.master, BINLOG_OP_PURGE, ["SUPER", "REPLICATION SLAVE"], BINLOG_OP_PURGE_DESC, self.verbosity, self._report) # Get binlog info binlog_file_name, active_binlog_file, active_binlog_index = ( get_binlog_info(self.master, reporter=self._report, server_name="master", verbosity=self.verbosity)) # Verify this Master has at least one slave. if not self.slaves: errormsg = (_CAN_NOT_VERIFY_SLAVES_STATUS.format( host=self.master.host, port=self.master.port)) raise UtilError(errormsg) # verify the given slaves are connected to this Master. if self.slaves_cnx_val and self.slaves: for slave in self.slaves: slave['instance'].is_configured_for_master(self.master, verify_state=False, raise_error=True) # IO running verification for --slaves option if not slave['instance'].is_connected(): if self.verbosity: self._report("# Slave '{0}:{1}' IO not running" "".format(slave['host'], slave['port'])) raise UtilError( _CAN_NOT_VERIFY_SLAVE_STATUS.format( host=slave['host'], port=slave['port'])) target_binlog_index = self.get_target_binlog_index(binlog_file_name) index_last_in_use = determine_purgeable_binlogs( active_binlog_index, self.slaves, reporter=self._report, verbosity=self.verbosity) self._purge(index_last_in_use, active_binlog_file, binlog_file_name, target_binlog_index, server=self.master, server_is_master=True)