25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Copy, fix and document export2odbc command from mod_admin_extra.erl

This commit is contained in:
Badlop 2012-11-26 13:22:29 +01:00
parent 9208f4dd50
commit 2c26926689
3 changed files with 32 additions and 1 deletions

View File

@ -5145,6 +5145,8 @@ The most interesting ones are:
from other Jabber/XMPP servers from other Jabber/XMPP servers
There exist tutorials to There exist tutorials to
\footahref{http://www.ejabberd.im/migrate-to-ejabberd}{migrate from other software to ejabberd}. \footahref{http://www.ejabberd.im/migrate-to-ejabberd}{migrate from other software to ejabberd}.
\titem{export2odbc virtualhost directory} \ind{export mnesia data to SQL files}
Export virtual host information from Mnesia tables to SQL files.
\titem{delete\_expired\_messages} This option can be used to delete old messages \titem{delete\_expired\_messages} This option can be used to delete old messages
in offline storage. This might be useful when the number of offline messages in offline storage. This might be useful when the number of offline messages
is very high. is very high.

View File

@ -41,6 +41,7 @@
%% Purge DB %% Purge DB
delete_expired_messages/0, delete_old_messages/1, delete_expired_messages/0, delete_old_messages/1,
%% Mnesia %% Mnesia
export2odbc/2,
set_master/1, set_master/1,
backup_mnesia/1, restore_mnesia/1, backup_mnesia/1, restore_mnesia/1,
dump_mnesia/1, dump_table/2, load_mnesia/1, dump_mnesia/1, dump_table/2, load_mnesia/1,
@ -165,6 +166,11 @@ commands() ->
module = mod_pubsub, function = rename_default_nodeplugin, module = mod_pubsub, function = rename_default_nodeplugin,
args = [], result = {res, rescode}}, args = [], result = {res, rescode}},
#ejabberd_commands{name = export2odbc, tags = [mnesia],
desc = "Export virtual host information from Mnesia tables to SQL files",
module = ?MODULE, function = export2odbc,
args = [{host, string}, {directory, string}],
result = {res, rescode}},
#ejabberd_commands{name = set_master, tags = [mnesia], #ejabberd_commands{name = set_master, tags = [mnesia],
desc = "Set master node of the clustered Mnesia tables", desc = "Set master node of the clustered Mnesia tables",
longdesc = "If you provide as nodename \"self\", this " longdesc = "If you provide as nodename \"self\", this "
@ -388,6 +394,23 @@ delete_old_messages(Days) ->
%%% Mnesia management %%% Mnesia management
%%% %%%
export2odbc(Host, Directory) ->
Tables = [{export_last, last},
{export_offline, offline},
{export_private_storage, private_storage},
{export_roster, roster},
{export_vcard, vcard},
{export_vcard_search, vcard_search},
{export_passwd, passwd}],
Export = fun({TableFun, Table}) ->
Filename = filename:join([Directory, atom_to_list(Table)++".txt"]),
io:format("Trying to export Mnesia table '~p' on Host '~s' to file '~s'~n", [Table, Host, Filename]),
Res = (catch ejd2odbc:TableFun(Host, Filename)),
io:format(" Result: ~p~n", [Res])
end,
lists:foreach(Export, Tables),
ok.
set_master("self") -> set_master("self") ->
set_master(node()); set_master(node());
set_master(NodeString) when is_list(NodeString) -> set_master(NodeString) when is_list(NodeString) ->

View File

@ -92,7 +92,13 @@
export_passwd(Server, Output) -> export_passwd(Server, Output) ->
export_common( export_common(
Server, passwd, Output, Server, passwd, Output,
fun(Host, {passwd, {LUser, LServer}, Password} = _R) fun(Host, {passwd, {LUser, LServer}, {scram, _, _, _, _}} = _R) ->
?INFO_MSG("You are trying to export the authentication "
"information of the account ~s@~s, but his password "
"is stored as SCRAM, and ejabberd ODBC authentication "
"doesn't support SCRAM.", [LUser, LServer]),
[];
(Host, {passwd, {LUser, LServer}, Password} = _R)
when LServer == Host -> when LServer == Host ->
Username = ejabberd_odbc:escape(LUser), Username = ejabberd_odbc:escape(LUser),
Pass = ejabberd_odbc:escape(Password), Pass = ejabberd_odbc:escape(Password),