mirror of
https://github.com/processone/ejabberd.git
synced 2025-01-01 17:53:00 +01:00
parent
ee3796b925
commit
20b4deffe3
@ -317,7 +317,8 @@ get_commands_spec() ->
|
|||||||
|
|
||||||
#ejabberd_commands{name = export2sql, tags = [mnesia],
|
#ejabberd_commands{name = export2sql, tags = [mnesia],
|
||||||
desc = "Export virtual host information from Mnesia tables to SQL file",
|
desc = "Export virtual host information from Mnesia tables to SQL file",
|
||||||
longdesc = "Configure the modules to use SQL, then call this command.",
|
longdesc = "Configure the modules to use SQL, then call this command. "
|
||||||
|
"After correct export, check 'delete_mnesia' too.",
|
||||||
module = ejd2sql, function = export,
|
module = ejd2sql, function = export,
|
||||||
args_desc = ["Vhost", "Full path to the destination SQL file"],
|
args_desc = ["Vhost", "Full path to the destination SQL file"],
|
||||||
args_example = ["example.com", "/var/lib/ejabberd/example.com.sql"],
|
args_example = ["example.com", "/var/lib/ejabberd/example.com.sql"],
|
||||||
|
@ -104,12 +104,17 @@ delete(Server) ->
|
|||||||
delete(Server, Module)
|
delete(Server, Module)
|
||||||
end, Modules).
|
end, Modules).
|
||||||
|
|
||||||
delete(Server, Module) ->
|
delete(Server, Module1) ->
|
||||||
LServer = jid:nameprep(iolist_to_binary(Server)),
|
LServer = jid:nameprep(iolist_to_binary(Server)),
|
||||||
|
Module = case Module1 of
|
||||||
|
mod_pubsub -> pubsub_db;
|
||||||
|
_ -> Module1
|
||||||
|
end,
|
||||||
|
SQLMod = gen_mod:db_mod(sql, Module),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({Table, ConvertFun}) ->
|
fun({Table, ConvertFun}) ->
|
||||||
delete(LServer, Table, ConvertFun)
|
delete(LServer, Table, ConvertFun)
|
||||||
end, Module:export(Server)).
|
end, SQLMod:export(Server)).
|
||||||
|
|
||||||
import(Server, Dir, ToType) ->
|
import(Server, Dir, ToType) ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
@ -192,7 +197,7 @@ output(_LServer, Table, Fd, SQLs) ->
|
|||||||
delete(LServer, Table, ConvertFun) ->
|
delete(LServer, Table, ConvertFun) ->
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
mnesia:write_lock_table(Table),
|
mnesia:write_lock_table(Table),
|
||||||
{_N, SQLs} =
|
{_N, _SQLs} =
|
||||||
mnesia:foldl(
|
mnesia:foldl(
|
||||||
fun(R, Acc) ->
|
fun(R, Acc) ->
|
||||||
case ConvertFun(LServer, R) of
|
case ConvertFun(LServer, R) of
|
||||||
@ -203,8 +208,7 @@ delete(LServer, Table, ConvertFun) ->
|
|||||||
Acc
|
Acc
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
{0, []}, Table),
|
{0, []}, Table)
|
||||||
delete(LServer, Table, SQLs)
|
|
||||||
end,
|
end,
|
||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user