Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)