# HG changeset patch # User Kim Alvefur # Date 1440605011 -7200 # Node ID 8df071457dee888237838433935a19df2576b1bb # Parent 4c2146f5bf39145a3d202b7bbbebb4f719b667b3 mod_migrate: Provides a prosodyctl mod_migrate command for copying data between storage backends diff -r 4c2146f5bf39 -r 8df071457dee mod_migrate/README.wiki --- /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 [users]*}}} + +`` would be e.g. `accounts` or `private` + +`` 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. diff -r 4c2146f5bf39 -r 8df071457dee mod_migrate/mod_migrate.lua --- /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 [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