Esempio n. 1
0
def get_rollback_sql(sql_id):
    aa = time.time()
    result = common_util.Entity()
    sql_info = get_sql_info_by_id(sql_id)
    result.rollback_sql = []
    result.rollback_sql_value = ""
    result.is_backup = sql_info.is_backup
    result.host_id = sql_info.mysql_host_id
    if (sql_info.is_backup):
        if (sql_info.rollback_sql is not None):
            result.rollback_sql_value = sql_info.rollback_sql
        else:
            for info in json.loads(sql_info.return_value):
                info = common_util.get_object(info)
                if (info.backup_dbname is None):
                    continue
                sql = "select schema_name from information_schema.SCHEMATA where schema_name = '{0}';".format(info.backup_dbname)
                db_name = db_util.DBUtil().fetchone(settings.MySQL_HOST, sql)
                if (db_name is None):
                    continue
                sql = "select tablename from {0}.$_$Inception_backup_information$_$ where opid_time = {1}".format(info.backup_dbname, info.sequence)
                table_name_dict = db_util.DBUtil().fetchone(settings.MySQL_HOST, sql)
                if (table_name_dict is None):
                    continue
                sql = "select rollback_statement from {0}.{1} where opid_time = {2}".format(info.backup_dbname, table_name_dict["tablename"], info.sequence)
                for list_dict in db_util.DBUtil().fetchall(settings.MySQL_HOST, sql):
                    result.rollback_sql.append(list_dict.values()[0])
    bb = time.time()
    print(">>>>>>>>>>>>>>get rollback sql time:{0}<<<<<<<<<<<<<<<<<<<".format(bb - aa))
    if (len(result.rollback_sql) > 0):
        result.rollback_sql_value = "\n".join(result.rollback_sql)
        result.rollback_sql = []
        db_util.DBUtil().execute(settings.MySQL_HOST,
                                 "update mysql_audit.sql_work set `rollback_sql` = '{0}' where id = {1};".format(db_util.DBUtil().escape(result.rollback_sql_value), sql_id))
    return result
Esempio n. 2
0
def get_object(rows, fields=None):
    result = []
    if (rows is None or len(rows) <= 0 or fields is None or len(fields) <= 0):
        return result
    for row in rows:
        info = common_util.Entity()
        for i in range(0, len(fields)):
            setattr(info, fields[i].lower(), row[i])
        result.append(info)
    return result
Esempio n. 3
0
def check_sql_audit_result_has_warnings(sql_id):
    result = common_util.Entity()
    sql_info = get_sql_info_by_id(sql_id)
    for info in json.loads(sql_info.audit_result_value):
        obj = common_util.get_object(info)
        if (obj.errlevel == settings.INCETION_SQL_WARNING):
            result.has_warnings = True
            break
        else:
            result.has_warnings = False
    return json.dumps(result, default=lambda o: o.__dict__)