Skip to content

Commit 724b416

Browse files
committed
Add export_db_ext command for db export to json
1 parent 1e8026a commit 724b416

2 files changed

Lines changed: 319 additions & 281 deletions

File tree

src/ejabberd_admin.erl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
gc/0,
6868
get_commands_spec/0,
6969
delete_old_messages_batch/4, delete_old_messages_status/1, delete_old_messages_abort/1,
70+
export_db_ext/4,
7071
%% Internal
7172
mnesia_list_tables/0,
7273
mnesia_table_details/1,
@@ -466,6 +467,19 @@ get_commands_spec() ->
466467
result = {res, restuple},
467468
result_desc = "Result tuple",
468469
result_example = {ok, <<"Export started">>}},
470+
#ejabberd_commands{name = export_db_ext, tags = [db],
471+
desc = "Export database records for host to files",
472+
note = "added in 26.XX",
473+
module = ejabberd_admin, function = export_db_ext,
474+
args_desc = ["Name of host that should be exported",
475+
"Directory name where exported files should be created",
476+
"List of modules separated by ',' that should be exported, use 'all' to use all available",
477+
"Type of serialization, recognized values are dbser and json"],
478+
args_example = [<<"localhost">>, <<"/home/ejabberd/export">>, <<"all">>, <<"json">>],
479+
args = [{host, binary}, {dir, binary}, {modules, binary}, {type, binary}],
480+
result = {res, restuple},
481+
result_desc = "Result tuple",
482+
result_example = {ok, <<"Export started">>}},
469483
#ejabberd_commands{name = export_db_status, tags = [db],
470484
desc = "Return current status of export operation",
471485
note = "added in 26.01",
@@ -1063,6 +1077,19 @@ import_dir(Path) ->
10631077
{cannot_import_dir, String}
10641078
end.
10651079

1080+
export_db_ext(Host, Dir, <<"all">>, Type) ->
1081+
export_db_ext(Host, Dir, undefined, Type);
1082+
export_db_ext(Host, Dir, Modules, Type) when is_binary(Modules) ->
1083+
Mods = [binary_to_atom(M, latin1) || M <- binary:split(Modules, <<",">>, [global])],
1084+
export_db_ext(Host, Dir, Mods, Type);
1085+
export_db_ext(Host, Dir, Mods, <<"json">>) ->
1086+
ejabberd_db_serialize:export(Host, Dir, Mods, json);
1087+
export_db_ext(Host, Dir, Mods, <<"dbser">>) ->
1088+
ejabberd_db_serialize:export(Host, Dir, Mods, dbser).
1089+
1090+
1091+
1092+
10661093
%%%
10671094
%%% Purge DB
10681095
%%%

0 commit comments

Comments
 (0)