mod_migrate: Provides a prosodyctl mod_migrate command for copying data between storage backends
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_migrate/README.wiki Wed Aug 26 18:03:31 2015 +0200
@@ -0,0 +1,19 @@
+#summary prosodyctl cross storage driver migration tool
+
+= Description =
+
+This module adds a command to `prosodyctl` for copying data between storage drivers.
+
+Usage: {{{prosodyctl mod_migrate example.com <source-store> <targer-driver> [users]*}}}
+
+`<source-store>` would be e.g. `accounts` or `private`
+
+`<target-driver>` is the storage driver to copy data to, sans the `mod_storage_` prefix.
+
+The process is something like this:
+
+1. Decide on the future configuration and add this to your prosody config.
+2. With Prosody shut down, run `prosodyctl mod_migrate example.com accounts sql`
+3. Repeat for each store, substituting 'accounts'. E.g. vcards, private...
+4. Change the `storage` configuration to use the new driver.
+5. Start prosody again.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mod_migrate/mod_migrate.lua Wed Aug 26 18:03:31 2015 +0200
@@ -0,0 +1,34 @@
+-- mod_migrate
+
+local sm = require"core.storagemanager";
+local um = require"core.usermanager";
+local mm = require"core.modulemanager";
+
+function module.command(arg)
+ local host, source_store, migrate_to, user = unpack(arg);
+ if not migrate_to then
+ return print("Usage: prosodyctl mod_migrate example.com <source-store> <targer-driver> [users]*");
+ end
+ sm.initialize_host(host);
+ um.initialize_host(host);
+ local module = module:context(host);
+ local storage = module:open_store(source_store);
+ local target = assert(sm.load_driver(host, migrate_to));
+ target = assert(target:open(source_store));
+ local function migrate_user(username)
+ module:log("info", "Migrating data for %s", username);
+ local data, err = storage:get(username);
+ assert(data or err==nil, err);
+ assert(target:set(username, data));
+ end
+
+ if arg[4] then
+ for i = 4, #arg do
+ migrate_user(arg[i]);
+ end
+ else
+ for user in um.users(host) do
+ migrate_user(user);
+ end
+ end
+end