我不认为这可以在单个节点上在线完成(任何人?),但除了运行两个节点和添加表副本之外,还可以通过备份/恢复来完成。在Mnesia 用户指南第 6.9.1 节中,您会发现一些代码使用 mnesia:traverse_backup 来更改 mnesia 备份文件中模式表(如下所示)中的节点名称。您可能应该使用的模块名称是mnesia_backup
.
使用此代码,您需要:
%% On mypl@machine1
mnesia:backup("/path/to/mnesia.backup").
change_node_name(mnesia_backup, mypl@machine1, mypl@machine2,
"/path/to/mnesia.backup", "/path/to/new.mnesia.backup").
%% On mypl@machine2
mnesia:restore("/path/to/new.mnesia.backup", []).
我不确定您是否需要先在mypl@machine2
.
用户指南中的更改节点名称代码:
change_node_name(Mod, From, To, Source, Target) ->
Switch =
fun(Node) when Node == From -> To;
(Node) when Node == To -> throw({error, already_exists});
(Node) -> Node
end,
Convert =
fun({schema, db_nodes, Nodes}, Acc) ->
{[{schema, db_nodes, lists:map(Switch,Nodes)}], Acc};
({schema, version, Version}, Acc) ->
{[{schema, version, Version}], Acc};
({schema, cookie, Cookie}, Acc) ->
{[{schema, cookie, Cookie}], Acc};
({schema, Tab, CreateList}, Acc) ->
Keys = [ram_copies, disc_copies, disc_only_copies],
OptSwitch =
fun({Key, Val}) ->
case lists:member(Key, Keys) of
true -> {Key, lists:map(Switch, Val)};
false-> {Key, Val}
end
end,
{[{schema, Tab, lists:map(OptSwitch, CreateList)}], Acc};
(Other, Acc) ->
{[Other], Acc}
end,
mnesia:traverse_backup(Source, Mod, Target, Mod, Convert, switched).