如何从 mnesia 备份/恢复单个表?

发布于 2024-09-19 03:05:45 字数 109 浏览 6 评论 0原文

我有一些带有 Disc_only_copies 类型的大表。 现在我需要将短节点名称更改为长节点名称,但由于 RAM 限制而无法做到这一点...

我可以部分使用备份/恢复数据库(逐表)吗?

I have some big tables with disc_only_copies type.
Now I need change short node name to long but cannot do it with RAM limitation...

Can I use backup/restore database partly (table by table)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦与时光遇 2024-09-26 03:05:45
    -module(test).
    -compile(export_all).

    -record(tab, {first, second}).

    do() ->
            mnesia:create_schema([node()]),
            mnesia:start(),
            mnesia:create_table(tab, [{disc_copies, [node()]}, {attributes, record_info(fields, tab)}]),
            mnesia:dirty_write({tab, 1, 2}),
            mnesia:dirty_write({tab, a, b}),
            mnesia:stop().

    change_node('extra@localhost') ->
            '[email protected]';
    change_node('ejabberd@localhost') ->
            '[email protected]';
    change_node(Node) ->
            Node.

    handle_nodes(Nodes) ->
            lists:map(fun(Node) ->
                    change_node(Node)
            end, Nodes -- [one@badhost, extra@badhost]).

    handle_cookie({TS, Node}) ->
            {TS, change_node(Node)}.

    handle_version_value([]) ->
            [];
    handle_version_value({'one@badhost', _}) ->
            [];
    handle_version_value({'extra@badhost', _}) ->
            [];
    handle_version_value({Node, TS}) ->
            {change_node(Node), TS}.

    handle_version({Key, Value}) ->
            {Key, handle_version_value(Value)}.

    handle_def(Def) ->
            lists:map(fun({Key, Value} = Property) ->
                    case Key of
                    ram_copies ->
                            {Key, handle_nodes(Value)};
                    disc_copies ->
                            {Key, handle_nodes(Value)};
                    disc_only_copies ->
                            {Key, handle_nodes(Value)};
                    cookie ->
                            {Key, handle_cookie(Value)};
                    version ->
                            {Key, handle_version(Value)};
                    _ ->
                            Property
                    end

        end, Def).

go() ->
        {ok, N} = dets:open_file(schema, [{file, "./schema.DAT"},{repair,false}, {keypos, 2}]),
        do2(N),
        dets:sync(N),
        dets:close(N).

do2(N) ->
        do2(N, dets:first(N)).

do2(_N, '$end_of_table') ->
        ok;
do2(N, Key) ->
        io:format("process: ~p~n", [Key]),
        [{N, Tab, Def}] = dets:lookup(N, Key),
        NewDef = handle_def(Def),
        dets:insert(N, {N, Tab, NewDef}),
%       file:write_file("schema.txt", io_lib:format("~p~n", [{N, Tab, NewDef}]), [append]),
        do2(N, dets:next(N, Key)).
    -module(test).
    -compile(export_all).

    -record(tab, {first, second}).

    do() ->
            mnesia:create_schema([node()]),
            mnesia:start(),
            mnesia:create_table(tab, [{disc_copies, [node()]}, {attributes, record_info(fields, tab)}]),
            mnesia:dirty_write({tab, 1, 2}),
            mnesia:dirty_write({tab, a, b}),
            mnesia:stop().

    change_node('extra@localhost') ->
            '[email protected]';
    change_node('ejabberd@localhost') ->
            '[email protected]';
    change_node(Node) ->
            Node.

    handle_nodes(Nodes) ->
            lists:map(fun(Node) ->
                    change_node(Node)
            end, Nodes -- [one@badhost, extra@badhost]).

    handle_cookie({TS, Node}) ->
            {TS, change_node(Node)}.

    handle_version_value([]) ->
            [];
    handle_version_value({'one@badhost', _}) ->
            [];
    handle_version_value({'extra@badhost', _}) ->
            [];
    handle_version_value({Node, TS}) ->
            {change_node(Node), TS}.

    handle_version({Key, Value}) ->
            {Key, handle_version_value(Value)}.

    handle_def(Def) ->
            lists:map(fun({Key, Value} = Property) ->
                    case Key of
                    ram_copies ->
                            {Key, handle_nodes(Value)};
                    disc_copies ->
                            {Key, handle_nodes(Value)};
                    disc_only_copies ->
                            {Key, handle_nodes(Value)};
                    cookie ->
                            {Key, handle_cookie(Value)};
                    version ->
                            {Key, handle_version(Value)};
                    _ ->
                            Property
                    end

        end, Def).

go() ->
        {ok, N} = dets:open_file(schema, [{file, "./schema.DAT"},{repair,false}, {keypos, 2}]),
        do2(N),
        dets:sync(N),
        dets:close(N).

do2(N) ->
        do2(N, dets:first(N)).

do2(_N, '$end_of_table') ->
        ok;
do2(N, Key) ->
        io:format("process: ~p~n", [Key]),
        [{N, Tab, Def}] = dets:lookup(N, Key),
        NewDef = handle_def(Def),
        dets:insert(N, {N, Tab, NewDef}),
%       file:write_file("schema.txt", io_lib:format("~p~n", [{N, Tab, NewDef}]), [append]),
        do2(N, dets:next(N, Key)).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文