Hello,
I have mnesia database which I want to change its node name, I have followed erlang official documentation and end up by this code which I run on :firstnode@host
:
:mnesia.stop()
:mnesia.start()
Process.sleep(200)
:mnesia.backup('backup.bup')
change_node_name(:mnesia_backup, :firstnode@host, :secondnode@host, 'backup.bup', 'new_backup.bup')
###########
defp change_node_name(mod, from, to, source, target) do
switch =
fn(node) when node == from ->
to
(node) when node == to ->
throw({:error, :already_exists})
(node) -> node
end
convert =
fn({: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, create_list}, acc) ->
keys = [:ram_copies, :disc_copies, :disc_only_copies]
opt_switch =
fn({key, val}) ->
case :lists.member(key, keys) do
true ->
{key, :lists.map(switch, val)}
false->
{key, val}
end
end
{[{:schema, tab, :lists.map(opt_switch, create_list)}], acc}
(other, acc) ->
{[other], acc}
end
:mnesia.traverse_backup(source, mod, target, mod, convert, :switched)
end
And when trying to restore the new backend from :secondnode@host
, the database still remote.
I did a lookup inside this code, the most important part is {:schema, :db_nodes, nodes} however this clause has never been matched, also (other, acc) has not matched, the only matched clause is {:schema, tab, create_list}, so any help please ? thank you.