Exemplo n.º 1
0
def mysql_threads_check(host, port, socket):
    try:
        mysqlbase = mysqllib.MySQLBase(host,
                                       port,
                                       backup_user,
                                       backup_passwd,
                                       unix_socket=socket)
        rows = mysqlbase.query('show slave status;')
        if rows:
            if rows[0]['Slave_IO_Running'].lower(
            ) == 'yes' and rows[0]['Slave_SQL_Running'].lower() == 'yes':
                return {
                    'status': 0,
                    'result': {
                        'Slave_IO_Running': rows[0]['Slave_IO_Running'],
                        'Slave_SQL_Running': rows[0]['Slave_SQL_Running']
                    }
                }
            else:
                return {
                    'status': -1,
                    'result': {
                        'Last_Errno': rows[0]['Last_Errno'],
                        'Last_Error': rows[0]['Last_Error'],
                        'Slave_IO_Running': rows[0]['Slave_IO_Running'],
                        'Slave_SQL_Running': rows[0]['Slave_SQL_Running']
                    }
                }
    except Exception, e:
        raise e
Exemplo n.º 2
0
def mysql_connection_check(host, port, socket):
    try:
        mysqlbase = mysqllib.MySQLBase(host,
                                       port,
                                       backup_user,
                                       backup_passwd,
                                       unix_socket=socket)
        mysqlbase.query('select 1;')
        return True
    except Exception, e:
        return False
Exemplo n.º 3
0
def dblog(dblog_msg, dblog_status):
    try:
        if dblog_status is False:
            return
        dblog_msg['extra_info'] = mysqllib.escape_string(
            dblog_msg['extra_info'])
        cond_list = ["%s='%s'" % (k, v) for k, v in dblog_msg.items()]
        sql = '''replace into db_backup_status set %s;''' % ','.join(cond_list)
        mysqlbase = mysqllib.MySQLBase(metadb_host,
                                       metadb_port,
                                       backup_user,
                                       backup_passwd,
                                       db=metadb_dbname)
        mysqlbase.query(sql, fetch=False)
    except Exception, e:
        log('dblog failed for %s' % str(e), level='error')
Exemplo n.º 4
0
def start_slave(host, port, socket):
    try:
        mysqlbase = mysqllib.MySQLBase(host,
                                       port,
                                       backup_user,
                                       backup_passwd,
                                       unix_socket=socket)
        rows = mysqlbase.query('show slave status;')
        if rows:
            if rows[0]['Slave_IO_Running'].lower(
            ) == 'yes' and rows[0]['Slave_SQL_Running'].lower() == 'yes':
                pass
            else:
                mysqlbase.query('start slave;', fetch=False)
                time.sleep(5)
                return mysqlbase.query('show slave status;')
    except Exception, e:
        raise e