migrator: Add option to keep going despite errors
authorKim Alvefur <zash@zash.se>
Sun, 09 Jan 2022 16:08:15 +0100
changeset 12170 39483b4099b4
parent 12169 79a51a48bdaf
child 12171 03f551510b1e
migrator: Add option to keep going despite errors
tools/migration/prosody-migrator.lua
--- a/tools/migration/prosody-migrator.lua	Sun Jan 09 15:52:50 2022 +0100
+++ b/tools/migration/prosody-migrator.lua	Sun Jan 09 16:08:15 2022 +0100
@@ -37,6 +37,7 @@
 local function usage()
 	print("Usage: " .. arg[0] .. " [OPTIONS] FROM_STORE TO_STORE");
 	print("  --config FILE         Specify config file")
+	print("  --keep-going          Keep going in case of errors");
 	print("  -v, --verbose         Incease log-level");
 	print("");
 	print("If no stores are specified, 'input' and 'output' are used.");
@@ -183,6 +184,19 @@
 	end;
 }
 
+if options["keep-going"] then
+	local xpcall = require "util.xpcall".xpcall;
+	local function log_err(err)
+		log("error", "Error migrating data: %s", err);
+		log("debug", "%s", debug.traceback());
+	end
+	for t, f in pairs(migrate_once) do
+		migrate_once[t] = function (origin, destination, user)
+			xpcall(f, log_err, origin, destination, user);
+		end
+	end
+end
+
 local migration_runner = async.runner(function (job)
 	for host, stores in pairs(job.input.hosts) do
 		prosody.hosts[host] = startup.make_host(host);