我有一个来自3节点Mnesia集群(生产集群)的备份,我想将其恢复到2节点集群(我用它来进行开发以重现bug)。如果群集具有相同数量的节点,则会遵循概述的here配方。如何从备份中删除节点?这可能吗?
我尝试更改子句({schema,db_nodes,Nodes},Acc)以返回较小的节点列表,但这似乎不起作用(或者它可能有效,但是不够)。
答案 0 :(得分:1)
事实证明这可以很容易地完成:
#!/usr/bin/env escript
change_node_name(Mod, Source, Target) ->
% Change this to whatever you want the new node list to be,
% with however many nodes, whatever names, etc.
ChangeNodes =
fun(_Nodes) ->
['node1@jamie.kingsbery.net','node2@jamie.kingsbery.net']
end,
Convert =
fun({schema, db_nodes, Nodes}, Acc) ->
{[{schema, db_nodes, ChangeNodes(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, ChangeNodes(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).
main(_Args)->
change_node_name(mnesia_backup,"/tmp/source-backup","dest-backup").