2013-10-21 53 views
1

我從一個3節點Mnesia羣集(一個生產羣集)備份,我想要將它還原到2節點羣集(我用於開發目的來重現錯誤)。如果羣集節點數量相同,則可以按照here概述的配方進行操作。如何從備份中刪除節點?這可能嗎?我試着改變子句({schema,db_nodes,Nodes},Acc)來返回一個較小的節點列表,但這似乎不起作用(或者它可能工作,但不足)。將Mnesia備份傳輸到較小的羣集

回答

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) -> 
      ['[email protected]','[email protected]'] 
     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").