Comparison

mod_migrate/mod_migrate.lua @ 1791:8df071457dee

mod_migrate: Provides a prosodyctl mod_migrate command for copying data between storage backends
author Kim Alvefur <zash@zash.se>
date Wed, 26 Aug 2015 18:03:31 +0200
child 1812:22b799c7b50a
comparison
equal deleted inserted replaced
1790:4c2146f5bf39 1791:8df071457dee
1 -- mod_migrate
2
3 local sm = require"core.storagemanager";
4 local um = require"core.usermanager";
5 local mm = require"core.modulemanager";
6
7 function module.command(arg)
8 local host, source_store, migrate_to, user = unpack(arg);
9 if not migrate_to then
10 return print("Usage: prosodyctl mod_migrate example.com <source-store> <targer-driver> [users]*");
11 end
12 sm.initialize_host(host);
13 um.initialize_host(host);
14 local module = module:context(host);
15 local storage = module:open_store(source_store);
16 local target = assert(sm.load_driver(host, migrate_to));
17 target = assert(target:open(source_store));
18 local function migrate_user(username)
19 module:log("info", "Migrating data for %s", username);
20 local data, err = storage:get(username);
21 assert(data or err==nil, err);
22 assert(target:set(username, data));
23 end
24
25 if arg[4] then
26 for i = 4, #arg do
27 migrate_user(arg[i]);
28 end
29 else
30 for user in um.users(host) do
31 migrate_user(user);
32 end
33 end
34 end