Comparison

tools/migration/prosody-migrator.lua @ 12166:39483b4099b4

migrator: Add option to keep going despite errors
author Kim Alvefur <zash@zash.se>
date Sun, 09 Jan 2022 16:08:15 +0100
parent 12165:79a51a48bdaf
child 12167:03f551510b1e
comparison
equal deleted inserted replaced
12165:79a51a48bdaf 12166:39483b4099b4
35 local default_config = (CFG_CONFIGDIR or ".").."/migrator.cfg.lua"; 35 local default_config = (CFG_CONFIGDIR or ".").."/migrator.cfg.lua";
36 36
37 local function usage() 37 local function usage()
38 print("Usage: " .. arg[0] .. " [OPTIONS] FROM_STORE TO_STORE"); 38 print("Usage: " .. arg[0] .. " [OPTIONS] FROM_STORE TO_STORE");
39 print(" --config FILE Specify config file") 39 print(" --config FILE Specify config file")
40 print(" --keep-going Keep going in case of errors");
40 print(" -v, --verbose Incease log-level"); 41 print(" -v, --verbose Incease log-level");
41 print(""); 42 print("");
42 print("If no stores are specified, 'input' and 'output' are used."); 43 print("If no stores are specified, 'input' and 'output' are used.");
43 end 44 end
44 45
181 assert(destination:append(user, id, item, when, with)); 182 assert(destination:append(user, id, item, when, with));
182 end 183 end
183 end; 184 end;
184 } 185 }
185 186
187 if options["keep-going"] then
188 local xpcall = require "util.xpcall".xpcall;
189 local function log_err(err)
190 log("error", "Error migrating data: %s", err);
191 log("debug", "%s", debug.traceback());
192 end
193 for t, f in pairs(migrate_once) do
194 migrate_once[t] = function (origin, destination, user)
195 xpcall(f, log_err, origin, destination, user);
196 end
197 end
198 end
199
186 local migration_runner = async.runner(function (job) 200 local migration_runner = async.runner(function (job)
187 for host, stores in pairs(job.input.hosts) do 201 for host, stores in pairs(job.input.hosts) do
188 prosody.hosts[host] = startup.make_host(host); 202 prosody.hosts[host] = startup.make_host(host);
189 sm.initialize_host(host); 203 sm.initialize_host(host);
190 um.initialize_host(host); 204 um.initialize_host(host);