aboutsummaryrefslogtreecommitdiff
path: root/src/ejabberd_admin.erl
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2009-05-15 22:38:46 +0000
committerBadlop <badlop@process-one.net>2009-05-15 22:38:46 +0000
commit5a68b44be17e5547692f17ac0278153fd2d0a1d0 (patch)
treed2abd7825ef801eaa9173ecb3f16a5501e51bd99 /src/ejabberd_admin.erl
parentAllow to define additional Erlang options in ejabberdctl.cfg (thanks to Serge... (diff)
New command to convert mnesia nodename, copied from OTP and Debian
SVN Revision: 2080
Diffstat (limited to 'src/ejabberd_admin.erl')
-rw-r--r--src/ejabberd_admin.erl52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/ejabberd_admin.erl b/src/ejabberd_admin.erl
index 8caf6e5ff..d7f00b185 100644
--- a/src/ejabberd_admin.erl
+++ b/src/ejabberd_admin.erl
@@ -42,6 +42,7 @@
dump_mnesia/1, load_mnesia/1,
install_fallback_mnesia/1,
dump_to_textfile/1,
+ mnesia_change_nodename/4,
restore/1 % Still used by some modules
]).
@@ -114,6 +115,12 @@ commands() ->
module = ?MODULE, function = delete_old_messages,
args = [{days, integer}], result = {res, rescode}},
+ #ejabberd_commands{name = mnesia_change_nodename, tags = [mnesia],
+ desc = "Change the erlang node name in a backup file",
+ module = ?MODULE, function = mnesia_change_nodename,
+ args = [{oldnodename, string}, {newnodename, string},
+ {oldbackup, string}, {newbackup, string}],
+ result = {res, restuple}},
#ejabberd_commands{name = backup, tags = [mnesia],
desc = "Store the database to backup file",
module = ?MODULE, function = backup_mnesia,
@@ -376,3 +383,48 @@ install_fallback_mnesia(Path) ->
{cannot_fallback, String}
end.
+mnesia_change_nodename(FromString, ToString, Source, Target) ->
+ From = list_to_atom(FromString),
+ To = list_to_atom(ToString),
+ Switch =
+ fun
+ (Node) when Node == From ->
+ io:format(" - Replacing nodename: '~p' with: '~p'~n", [From, To]),
+ To;
+ (Node) when Node == To ->
+ %% throw({error, already_exists});
+ io:format(" - Node: '~p' will not be modified (it is already '~p')~n", [Node, To]),
+ Node;
+ (Node) ->
+ io:format(" - Node: '~p' will not be modified (it is not '~p')~n", [Node, From]),
+ Node
+ end,
+ Convert =
+ fun
+ ({schema, db_nodes, Nodes}, Acc) ->
+ io:format(" +++ db_nodes ~p~n", [Nodes]),
+ {[{schema, db_nodes, lists:map(Switch,Nodes)}], Acc};
+ ({schema, version, Version}, Acc) ->
+ io:format(" +++ version: ~p~n", [Version]),
+ {[{schema, version, Version}], Acc};
+ ({schema, cookie, Cookie}, Acc) ->
+ io:format(" +++ cookie: ~p~n", [Cookie]),
+ {[{schema, cookie, Cookie}], Acc};
+ ({schema, Tab, CreateList}, Acc) ->
+ io:format("~n * Checking table: '~p'~n", [Tab]),
+ Keys = [ram_copies, disc_copies, disc_only_copies],
+ OptSwitch =
+ fun({Key, Val}) ->
+ case lists:member(Key, Keys) of
+ true ->
+ io:format(" + Checking key: '~p'~n", [Key]),
+ {Key, lists:map(Switch, Val)};
+ false-> {Key, Val}
+ end
+ end,
+ Res = {[{schema, Tab, lists:map(OptSwitch, CreateList)}], Acc},
+ Res;
+ (Other, Acc) ->
+ {[Other], Acc}
+ end,
+ mnesia:traverse_backup(Source, Target, Convert, switched).