Example #1
0
def db_sqlorder_osc(request, id):
    if request.method == "POST" and request.POST.get('model') == 'query':
        order = SQL_Audit_Order.objects.get(id=id)
        inceptRbt = Inception()
        sqlResultList = SQL_Order_Execute_Result.objects.filter(order=order)
        for ds in sqlResultList:
            if ds.backup_db.find('None') == -1:
                if ds.sqlsha:
                    result = inceptRbt.getOscStatus(sqlSHA1=ds.sqlsha)
                    if result.get('status') == 'success':
                        return JsonResponse({
                            "code": 200,
                            "data": result.get('data')
                        })
                    else:
                        return JsonResponse({
                            "code": 500,
                            "data": result.get('data')
                        })
    elif request.method == "POST" and request.POST.get('model') == 'stop':
        order = SQL_Audit_Order.objects.get(id=id)
        inceptRbt = Inception()
        sqlResultList = SQL_Order_Execute_Result.objects.filter(order=order)
        for ds in sqlResultList:
            if ds.backup_db.find('None') == -1:
                if ds.sqlsha:
                    result = inceptRbt.stopOsc(sqlSHA1=ds.sqlsha)
                    if result.get('status') == 'success':
                        return JsonResponse({
                            "code": 200,
                            "data": result.get('data')
                        })
                    else:
                        return JsonResponse({
                            "code": 500,
                            "data": result.get('errinfo')
                        })
Example #2
0
def db_sqlorder_osc(request,id):
    if request.method == "POST" and request.POST.get('model') == 'query':
        order = SQL_Audit_Order.objects.get(id=id)
        inceptRbt = Inception()           
        sqlResultList = SQL_Order_Execute_Result.objects.filter(order=order)
        for ds in sqlResultList:
            if ds.backup_db.find('None') == -1:
                if ds.sqlsha:
                    result = inceptRbt.getOscStatus(sqlSHA1=ds.sqlsha) 
                    if result.get('status') == 'success':
                        return JsonResponse({"code":200,"data":result.get('data')})
                    else:return JsonResponse({"code":500,"data":result.get('data')}) 
    elif request.method == "POST" and request.POST.get('model') == 'stop':
        order = SQL_Audit_Order.objects.get(id=id)
        inceptRbt = Inception()           
        sqlResultList = SQL_Order_Execute_Result.objects.filter(order=order)
        for ds in sqlResultList:
            if ds.backup_db.find('None') == -1:
                if ds.sqlsha:
                    result = inceptRbt.stopOsc(sqlSHA1=ds.sqlsha) 
                    if result.get('status') == 'success':
                        return JsonResponse({"code":200,"data":result.get('data')})
                    else:
                        return JsonResponse({"code":500,"data":result.get('errinfo')})
Example #3
0
 order.order_user = User.objects.get(id=order.order_user).username
 order.order_executor = User.objects.get(id=order.order_executor).username  
 try:
     order.sql_audit_order.order_db.db_service = Service_Assets.objects.get(id=order.sql_audit_order.order_db.db_service)
 except Exception, ex:
     order.sql_audit_order.order_db.db_service = '未知'
 if order.order_status in [5,6,9] and order.sql_audit_order.order_type=='online':   
     sqlResultList = SQL_Order_Execute_Result.objects.filter(order=order.sql_audit_order)
     for ds in sqlResultList:
         if ds.backup_db.find('None') == -1:
             result = inceptRbt.getRollBackTable(
                                            host=incept.db_backup_host, user=incept.db_backup_user, 
                                            passwd=incept.db_backup_passwd, dbName=ds.backup_db, 
                                            port=incept.db_backup_port, sequence=str(ds.sequence).replace('\'','')
                                            )
             if len(ds.sqlsha) > 0:oscStatus = inceptRbt.getOscStatus(sqlSHA1=ds.sqlsha)
             if result.get('status') == 'success' and result.get('data'):
                 tableName = result.get('data')[0]
                 rbkSql = inceptRbt.getRollBackSQL(
                                                host=incept.db_backup_host, user=incept.db_backup_user, 
                                                passwd=incept.db_backup_passwd, dbName=ds.backup_db, 
                                                port=incept.db_backup_port, tableName=tableName,
                                                sequence=str(ds.sequence).replace('\'',''),
                                                )
             else:
                 rollBackSql = ["Ops!数据库服务器 - {host} 可能未开启binlog或者未开启备份功能,获取回滚SQL失败。".format(host=order.sql_audit_order.order_db.db_host,dbname=order.sql_audit_order.order_db.db_name)]
                 return render(request,'database/db_sqlorder_run.html',{"user":request.user,"order":order,"sqlResultList":sqlResultList,"rollBackSql":rollBackSql,"rbkSql":0,"oscStatus":oscStatus})  
             if rbkSql.get('status') == 'success' and rbkSql.get('data'): 
                 for sql in rbkSql.get('data'):
                     rollBackSql.append(sql[0])  
 elif  order.sql_audit_order.order_type=='file':
Example #4
0
 except Exception, ex:
     order.order_db.db_service = '未知'
 if order.order_status in [2, 3, 7]:
     sqlResultList = SQL_Order_Execute_Result.objects.filter(
         order=order)
     for ds in sqlResultList:
         if ds.backup_db.find('None') == -1:
             result = inceptRbt.getRollBackTable(
                 host=incept.db_backup_host,
                 user=incept.db_backup_user,
                 passwd=incept.db_backup_passwd,
                 dbName=ds.backup_db,
                 port=incept.db_backup_port,
                 sequence=str(ds.sequence).replace('\'', ''))
             if len(ds.sqlsha) > 0:
                 oscStatus = inceptRbt.getOscStatus(sqlSHA1=ds.sqlsha)
             if result.get('status') == 'success' and result.get(
                     'data'):
                 tableName = result.get('data')[0]
                 rbkSql = inceptRbt.getRollBackSQL(
                     host=incept.db_backup_host,
                     user=incept.db_backup_user,
                     passwd=incept.db_backup_passwd,
                     dbName=ds.backup_db,
                     port=incept.db_backup_port,
                     tableName=tableName,
                     sequence=str(ds.sequence).replace('\'', ''),
                 )
             else:
                 rollBackSql = [
                     "Ops!数据库服务器 - {host} 可能未开启binlog或者未开启备份功能,获取回滚SQL失败。"
Example #5
0
                port=order.order_db.db_port
                )   
     try:
         order.order_db.db_service = Service_Assets.objects.get(id=order.order_db.db_service)
     except Exception, ex:
         order.order_db.db_service = '未知'
     if order.order_status in [2,3,7]:       
         sqlResultList = SQL_Order_Execute_Result.objects.filter(order=order)
         for ds in sqlResultList:
             if ds.backup_db.find('None') == -1:
                 result = inceptRbt.getRollBackTable(
                                                host=incept.db_backup_host, user=incept.db_backup_user, 
                                                passwd=incept.db_backup_passwd, dbName=ds.backup_db, 
                                                port=incept.db_backup_port, sequence=str(ds.sequence).replace('\'','')
                                                )
                 if len(ds.sqlsha) > 0:oscStatus = inceptRbt.getOscStatus(sqlSHA1=ds.sqlsha)
                 if result.get('status') == 'success' and result.get('data'):
                     tableName = result.get('data')[0]
                     rbkSql = inceptRbt.getRollBackSQL(
                                                    host=incept.db_backup_host, user=incept.db_backup_user, 
                                                    passwd=incept.db_backup_passwd, dbName=ds.backup_db, 
                                                    port=incept.db_backup_port, tableName=tableName,
                                                    sequence=str(ds.sequence).replace('\'',''),
                                                    )
                 else:
                     rollBackSql = ["Ops!数据库服务器 - {host} 可能未开启binlog或者未开启备份功能,获取回滚SQL失败。".format(host=order.order_db.db_host,dbname=order.order_db.db_name)]
                     return render(request,'database/db_sqlorder_run.html',{"user":request.user,"order":order,"sqlResultList":sqlResultList,"rollBackSql":rollBackSql,"rbkSql":0,"oscStatus":oscStatus})  
                 if rbkSql.get('status') == 'success' and rbkSql.get('data'): 
                     rollBackSql.append(rbkSql.get('data')[0])     
     return render(request,'database/db_sqlorder_run.html',{"user":request.user,"order":order,"sqlResultList":sqlResultList,"rollBackSql":rollBackSql,"oscStatus":oscStatus})