Example #1
0
def __dump_all(request, params):
    infos = {"status": False, "msg": ""}
    vars = demjson.decode(request.body)
    check_info = check(vars, db_tag=False, tb_tag=False)
    if check_info["status"]:
        s_dump = check_info["s_dump"]
        d_conn = check_info["d_conn"]
        rd_int = random.randint(0, 2**32)
        dump_command = """{s_dump} {param} -A all.sql-{rd_int} 2>/dev/null""".format(
            s_dump=s_dump, rd_int=rd_int, param=params)
        command = """{d_conn} < all.sql-{rd_int} 2>/dev/null""".format(
            rd_int=rd_int, d_conn=d_conn, param=params)
        if exec_cmd(dump_command):
            infos["dump_status"] = True
            if exec_cmd(import_command):
                infos["status"] = True
                os.remove("all.sql-{rd_int}".format(rd_int=rd_int))
            else:
                infos["msg"] = "exec import command failed"
                os.remove("all.sql-{rd_int}".format(rd_int=rd_int))
        else:
            infos["msg"] = "exec dump command failed"
            os.remove("all.sql-{rd_int}".format(rd_int=rd_int))
    else:
        return HttpResponse(demjson.encode(check_info))
    return HttpResponse(demjson.encode(infos))
Example #2
0
def __dump_table_by_where(request, params):
    infos = {"status": False, "msg": ""}
    vars = demjson.decode(request.body)
    check_info = check(vars, db_tag=True, tb_tag=True, where_tag=True)
    if check_info["status"]:
        s_dump = check_info["s_dump"]
        d_conn = check_info["d_conn"]
        rd_int = random.randint(0, 2**32)
        src_database = check_info["s_database"]
        dest_database = check_info["d_database"]
        table = check_info["table"]
        where = check_info["where"]
        dump_command = """{s_dump} {param} {src_database} {src_table} --where="{where}" {src_database}.{s_table}.sql-{rd_int} 2>/dev/null""".format(
            rd_int=rd_int,
            s_dump=s_dump,
            param=params,
            src_database=src_database,
            src_table=table,
            s_table=table.replace(" ", "-"),
            where=where)
        import_command = """{d_conn} {dest_database} {src_database}.{s_table}.sql-{rd_int} 2>/dev/null""".format(
            d_conn=d_conn,
            param=params,
            rd_int=rd_int,
            src_database=src_database,
            s_table=table.replace(" ", "-"),
            dest_database=dest_database,
            where=where)
        if exec_cmd(dump_command):
            infos["dump_status"] = True
            if exec_cmd(import_command):
                infos["status"] = True
                os.remove("{src_database}.{s_table}.sql-{rd_int}".format(
                    rd_int=rd_int,
                    src_database=src_database,
                    s_table=table.replace(" ", "-")))
            else:
                infos["msg"] = "exec import command failed"
                os.remove("{src_database}.{s_table}.sql-{rd_int}".format(
                    rd_int=rd_int,
                    src_database=src_database,
                    s_table=table.replace(" ", "-")))
        else:
            infos["msg"] = "exec dump command failed"
            os.remove("{src_database}.{s_table}.sql-{rd_int}".format(
                rd_int=rd_int,
                src_database=src_database,
                s_table=table.replace(" ", "-")))
    else:
        return HttpResponse(demjson.encode(check_info))
    return HttpResponse(demjson.encode(infos))
Example #3
0
def __dump_table(request, params):
    infos = {"status": False, "msg": ""}
    vars = demjson.decode(request.body)
    check_info = check(vars, db_tag=True, tb_tag=True)
    if check_info["status"]:
        date = time.strftime('%Y-%m-%d', time.localtime())
        dump = check_info["dump"]
        database = check_info["database"]
        table = check_info["table"]
        command = """{dump} {param} {database} {table} > {location}/{database}.{s_table}.sql-{date} 2>/dev/null """.format(
            date=date,
            dump=dump,
            param=params,
            database=database,
            location=location,
            table=table,
            s_table=table.replace(" ", "-"))
        if exec_cmd(command):
            infos["status"] = True
        else:
            infos["msg"] = "exec command failed"
            infos["msg"] = str(command)
    else:
        return HttpResponse(demjson.encode(check_info))
    return HttpResponse(demjson.encode(infos))
Example #4
0
def __dump_table_by_where(request, params):
    infos = {"status": False, "msg": ""}
    vars = demjson.decode(request.body)
    check_info = check(vars, db_tag=True, tb_tag=True, where_tag=True)
    if check_info["status"]:
        s_dump = check_info["s_dump"]
        d_conn = check_info["d_conn"]
        src_database = check_info["s_database"]
        dest_database = check_info["d_database"]
        table = check_info["table"]
        where = check_info["where"]
        command = """{s_dump} {param} {src_database} {src_table} --where="{where}" 2>/dev/null | {d_conn} {dest_database} 2>/dev/null""".format(
            s_dump=s_dump,
            d_conn=d_conn,
            param=params,
            src_database=src_database,
            src_table=table,
            dest_database=dest_database,
            where=where)
        if exec_cmd(command):
            infos["status"] = True
        else:
            infos["msg"] = "exec command failed"
    else:
        return HttpResponse(demjson.encode(check_info))
    return HttpResponse(demjson.encode(infos))
Example #5
0
def __dump_all(request, params):
    infos = {"status": False, "msg": ""}
    vars = demjson.decode(request.body)
    check_info = check(vars, db_tag=False, tb_tag=False)
    if check_info["status"]:
        dump = check_info["dump"]
        command = """{dump} {param} -A > {location}/{database}.{table}.sql-{date} 2>/dev/null""".format(
            dump=dump, date=date, param=params, location=location)
        if exec_cmd(command):
            infos["status"] = True
        else:
            infos["msg"] = "exec command failed"
    else:
        return HttpResponse(demjson.encode(check_info))
    return HttpResponse(demjson.encode(infos))
Example #6
0
def __dump_all(request, params):
    infos = {"status": False, "msg": ""}
    vars = demjson.decode(request.body)
    check_info = check(vars, db_tag=False, tb_tag=False)
    if check_info["status"]:
        s_dump = check_info["s_dump"]
        d_conn = check_info["d_conn"]
        command = """{s_dump} {param} -A 2>/dev/null | {d_conn} 2>/dev/null""".format(
            s_dump=s_dump, d_conn=d_conn, param=params)
        if exec_cmd(command):
            infos["status"] = True
        else:
            infos["msg"] = "exec command failed"
    else:
        return HttpResponse(demjson.encode(check_info))
    return HttpResponse(demjson.encode(infos))