Mercurial > prosody-hg
annotate tools/migration/prosody-migrator.lua @ 14229:ce31fdde0ad1 default tip
net.unbound: Simplify conditional
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 13 Jun 2026 11:35:18 +0200 |
| parents | af28d6debaca |
| children |
| rev | line source |
|---|---|
|
4216
ff80a8471e86
tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents:
4211
diff
changeset
|
1 #!/usr/bin/env lua |
|
ff80a8471e86
tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents:
4211
diff
changeset
|
2 |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
3 CFG_SOURCEDIR=CFG_SOURCEDIR or os.getenv("PROSODY_SRCDIR"); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
4 CFG_CONFIGDIR=CFG_CONFIGDIR or os.getenv("PROSODY_CFGDIR"); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
5 CFG_PLUGINDIR=CFG_PLUGINDIR or os.getenv("PROSODY_PLUGINDIR"); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
6 CFG_DATADIR=CFG_DATADIR or os.getenv("PROSODY_DATADIR"); |
|
4216
ff80a8471e86
tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents:
4211
diff
changeset
|
7 |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
8 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
9 |
|
14059
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
10 -- Check before first require, to preempt the probable failure |
|
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
11 if _VERSION < "Lua 5.2" then |
|
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
12 io.stderr:write("Prosody is no longer compatible with Lua 5.1\n") |
|
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
13 io.stderr:write("See https://prosody.im/doc/depends#lua for more information\n") |
|
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
14 return os.exit(1); |
|
4239
69fe5fd861e7
tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents:
4235
diff
changeset
|
15 end |
|
69fe5fd861e7
tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents:
4235
diff
changeset
|
16 |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
17 -- Tell Lua where to find our libraries |
|
14068
2462247ec377
prosody, prosodyctl: Always search installation directory first
Kim Alvefur <zash@zash.se>
parents:
14066
diff
changeset
|
18 -- and ensure that resources in the current directory are not picked up by accident |
|
2462247ec377
prosody, prosodyctl: Always search installation directory first
Kim Alvefur <zash@zash.se>
parents:
14066
diff
changeset
|
19 do |
|
14059
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
20 -- Installed instance |
|
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
21 local function is_relative(path) |
|
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
22 local path_sep = package.config:sub(1,1); |
|
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
23 return ((path_sep == "/" and path:sub(1,1) ~= "/") |
|
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
24 or (path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\"))) |
|
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
25 end |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
26 local function filter_relative_paths(path) |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
27 if is_relative(path) then return ""; end |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
28 end |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
29 local function sanitise_paths(paths) |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
30 return (paths:gsub("[^;]+;?", filter_relative_paths):gsub(";;+", ";")); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
31 end |
|
14068
2462247ec377
prosody, prosodyctl: Always search installation directory first
Kim Alvefur <zash@zash.se>
parents:
14066
diff
changeset
|
32 package.path = (CFG_SOURCEDIR or ".") .. "/?.lua;" .. sanitise_paths(package.path); |
|
2462247ec377
prosody, prosodyctl: Always search installation directory first
Kim Alvefur <zash@zash.se>
parents:
14066
diff
changeset
|
33 package.cpath = (CFG_SOURCEDIR or ".") .. "/?.so;" .. sanitise_paths(package.cpath); |
|
14059
2bdddcfad61d
migrator: Apply loader fix here too
Kim Alvefur <zash@zash.se>
parents:
13920
diff
changeset
|
34 |
|
14068
2462247ec377
prosody, prosodyctl: Always search installation directory first
Kim Alvefur <zash@zash.se>
parents:
14066
diff
changeset
|
35 if pcall(dofile, (CFG_SOURCEDIR or ".") .. "/loader.lua") then |
|
14066
b085d32af140
prosody, prosodyctl: Load loader directly from source directory
Kim Alvefur <zash@zash.se>
parents:
14059
diff
changeset
|
36 package.loaded["prosody.loader"] = true; |
|
b085d32af140
prosody, prosodyctl: Load loader directly from source directory
Kim Alvefur <zash@zash.se>
parents:
14059
diff
changeset
|
37 else |
|
b085d32af140
prosody, prosodyctl: Load loader directly from source directory
Kim Alvefur <zash@zash.se>
parents:
14059
diff
changeset
|
38 require "prosody.loader"; |
|
b085d32af140
prosody, prosodyctl: Load loader directly from source directory
Kim Alvefur <zash@zash.se>
parents:
14059
diff
changeset
|
39 end |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
40 end |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
41 |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
42 -- Substitute ~ with path to home directory in data path |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
43 if CFG_DATADIR then |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
44 if os.getenv("HOME") then |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
45 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME")); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
46 end |
|
4239
69fe5fd861e7
tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents:
4235
diff
changeset
|
47 end |
|
69fe5fd861e7
tools/migration: Support for ~/ in paths
Matthew Wild <mwild1@gmail.com>
parents:
4235
diff
changeset
|
48 |
|
4216
ff80a8471e86
tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents:
4211
diff
changeset
|
49 local default_config = (CFG_CONFIGDIR or ".").."/migrator.cfg.lua"; |
|
4211
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
50 |
|
12162
b7ee14ba09c9
migrator: Reuse earlier usage text
Kim Alvefur <zash@zash.se>
parents:
12161
diff
changeset
|
51 local function usage() |
|
12163
59b65cc6312f
migrator: Include --options in usage info
Kim Alvefur <zash@zash.se>
parents:
12162
diff
changeset
|
52 print("Usage: " .. arg[0] .. " [OPTIONS] FROM_STORE TO_STORE"); |
|
59b65cc6312f
migrator: Include --options in usage info
Kim Alvefur <zash@zash.se>
parents:
12162
diff
changeset
|
53 print(" --config FILE Specify config file") |
|
12166
39483b4099b4
migrator: Add option to keep going despite errors
Kim Alvefur <zash@zash.se>
parents:
12165
diff
changeset
|
54 print(" --keep-going Keep going in case of errors"); |
|
12387
05c250fa335a
Spelling: Fix various spelling mistakes (thanks timeless)
Kim Alvefur <zash@zash.se>
parents:
12168
diff
changeset
|
55 print(" -v, --verbose Increase log-level"); |
|
12163
59b65cc6312f
migrator: Include --options in usage info
Kim Alvefur <zash@zash.se>
parents:
12162
diff
changeset
|
56 print(""); |
|
12162
b7ee14ba09c9
migrator: Reuse earlier usage text
Kim Alvefur <zash@zash.se>
parents:
12161
diff
changeset
|
57 print("If no stores are specified, 'input' and 'output' are used."); |
|
b7ee14ba09c9
migrator: Reuse earlier usage text
Kim Alvefur <zash@zash.se>
parents:
12161
diff
changeset
|
58 end |
|
b7ee14ba09c9
migrator: Reuse earlier usage text
Kim Alvefur <zash@zash.se>
parents:
12161
diff
changeset
|
59 |
|
13142
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
60 if not pcall(require, "prosody.loader") then |
|
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
61 pcall(require, "loader"); |
|
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
62 end |
|
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
63 |
|
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
64 local startup = require "prosody.util.startup"; |
|
11728
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
65 do |
|
12161
6e7678f6fe9a
migrator: Customise cli argument parsing (--help, --verbose)
Kim Alvefur <zash@zash.se>
parents:
11731
diff
changeset
|
66 startup.parse_args({ |
|
6e7678f6fe9a
migrator: Customise cli argument parsing (--help, --verbose)
Kim Alvefur <zash@zash.se>
parents:
11731
diff
changeset
|
67 short_params = { v = "verbose", h = "help", ["?"] = "help" }; |
|
6e7678f6fe9a
migrator: Customise cli argument parsing (--help, --verbose)
Kim Alvefur <zash@zash.se>
parents:
11731
diff
changeset
|
68 value_params = { config = true }; |
|
6e7678f6fe9a
migrator: Customise cli argument parsing (--help, --verbose)
Kim Alvefur <zash@zash.se>
parents:
11731
diff
changeset
|
69 }); |
|
11728
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
70 startup.init_global_state(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
71 prosody.process_type = "migrator"; |
|
12161
6e7678f6fe9a
migrator: Customise cli argument parsing (--help, --verbose)
Kim Alvefur <zash@zash.se>
parents:
11731
diff
changeset
|
72 if prosody.opts.help then |
|
12162
b7ee14ba09c9
migrator: Reuse earlier usage text
Kim Alvefur <zash@zash.se>
parents:
12161
diff
changeset
|
73 usage(); |
|
12161
6e7678f6fe9a
migrator: Customise cli argument parsing (--help, --verbose)
Kim Alvefur <zash@zash.se>
parents:
11731
diff
changeset
|
74 os.exit(0); |
|
6e7678f6fe9a
migrator: Customise cli argument parsing (--help, --verbose)
Kim Alvefur <zash@zash.se>
parents:
11731
diff
changeset
|
75 end |
|
11728
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
76 startup.force_console_logging(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
77 startup.init_logging(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
78 startup.init_gc(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
79 startup.init_errors(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
80 startup.setup_plugindir(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
81 startup.setup_plugin_install_path(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
82 startup.setup_datadir(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
83 startup.chdir(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
84 startup.read_version(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
85 startup.switch_user(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
86 startup.check_dependencies(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
87 startup.log_startup_warnings(); |
|
11729
f37cafeb75d6
migrator: Trick net.server into thinking the config is loaded
Kim Alvefur <zash@zash.se>
parents:
11728
diff
changeset
|
88 prosody.config_loaded = true; |
|
11728
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
89 startup.load_libraries(); |
|
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
90 startup.init_http_client(); |
|
11731
076ceb405b94
migrator: Silence assert in core.moduleapi
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
91 prosody.core_post_stanza = function () |
|
076ceb405b94
migrator: Silence assert in core.moduleapi
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
92 -- silence assert in core.moduleapi |
|
076ceb405b94
migrator: Silence assert in core.moduleapi
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
93 error("Attempt to send stanzas from inside migrator.", 0); |
|
076ceb405b94
migrator: Silence assert in core.moduleapi
Kim Alvefur <zash@zash.se>
parents:
11730
diff
changeset
|
94 end |
|
11728
826d57c16d1c
migrator: Customise startup sequence to fix #1673 (Thanks acidsys)
Kim Alvefur <zash@zash.se>
parents:
10004
diff
changeset
|
95 end |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
96 |
|
4210
4583473dcce4
tools/migration/main.lua: Add command-line parsing, including --config=CONFIG_FILE, and the ability to specify to/from stores to migrate
Matthew Wild <mwild1@gmail.com>
parents:
4166
diff
changeset
|
97 -- Command-line parsing |
|
11730
9bf8a0607d12
migrator: Use parsed command line flags already parsed by util.startup
Kim Alvefur <zash@zash.se>
parents:
11729
diff
changeset
|
98 local options = prosody.opts; |
|
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4240
diff
changeset
|
99 |
|
13142
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
100 local envloadfile = require "prosody.util.envload".envloadfile; |
|
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4240
diff
changeset
|
101 |
|
4211
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
102 local config_file = options.config or default_config; |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
103 local from_store = arg[1] or "input"; |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
104 local to_store = arg[2] or "output"; |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
105 |
|
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
106 config = {}; |
|
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
107 local config_env = setmetatable({}, { __index = function(t, k) return function(tbl) config[k] = tbl; end; end }); |
|
7880
1d998891c967
migrator: Remove wrapper around envloadfile since envloadfile does the right thing in a compatible way
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
108 local config_chunk, err = envloadfile(config_file, config_env); |
|
4211
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
109 if not config_chunk then |
| 7895 | 110 print("There was an error loading the config file, check that the file exists"); |
|
4211
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
111 print("and that the syntax is correct:"); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
112 print("", err); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
113 os.exit(1); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
114 end |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
115 |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
116 config_chunk(); |
|
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
117 |
|
4211
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
118 local have_err; |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
119 if #arg > 0 and #arg ~= 2 then |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
120 have_err = true; |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
121 print("Error: Incorrect number of parameters supplied."); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
122 end |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
123 if not config[from_store] then |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
124 have_err = true; |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
125 print("Error: Input store '"..from_store.."' not found in the config file."); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
126 end |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
127 if not config[to_store] then |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
128 have_err = true; |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
129 print("Error: Output store '"..to_store.."' not found in the config file."); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
130 end |
|
4235
899ffc1674b5
tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents:
4229
diff
changeset
|
131 |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
132 for store, conf in pairs(config) do -- COMPAT |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
133 if conf.type == "prosody_files" then |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
134 conf.type = "internal"; |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
135 elseif conf.type == "prosody_sql" then |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
136 conf.type = "sql"; |
|
4235
899ffc1674b5
tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents:
4229
diff
changeset
|
137 end |
|
4211
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
138 end |
|
4235
899ffc1674b5
tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw
Matthew Wild <mwild1@gmail.com>
parents:
4229
diff
changeset
|
139 |
|
4211
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
140 if have_err then |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
141 print(""); |
|
12162
b7ee14ba09c9
migrator: Reuse earlier usage text
Kim Alvefur <zash@zash.se>
parents:
12161
diff
changeset
|
142 usage(); |
|
4211
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
143 print(""); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
144 print("The available stores in your migrator config are:"); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
145 print(""); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
146 for store in pairs(config) do |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
147 print("", store); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
148 end |
|
4216
ff80a8471e86
tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents:
4211
diff
changeset
|
149 print(""); |
|
4211
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
150 os.exit(1); |
|
9a12fc2baa37
tools/migration/*.lua: Rename config to migrator.cfg.lua, add error handling for config and command-line parameters
Matthew Wild <mwild1@gmail.com>
parents:
4210
diff
changeset
|
151 end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5021
diff
changeset
|
152 |
|
13142
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
153 local async = require "prosody.util.async"; |
|
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
154 local server = require "prosody.net.server"; |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
155 local watchers = { |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
156 error = function (_, err) |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
157 error(err); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
158 end; |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
159 waiting = function () |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
160 server.loop(); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
161 end; |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
162 }; |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
163 |
|
13142
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
164 local cm = require "prosody.core.configmanager"; |
|
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
165 local hm = require "prosody.core.hostmanager"; |
|
13920
2169be3581ae
migrator: Allow migrating between different configs of the same driver
Kim Alvefur <zash@zash.se>
parents:
13348
diff
changeset
|
166 local mm = require "prosody.core.modulemanager"; |
|
13142
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
167 local sm = require "prosody.core.storagemanager"; |
|
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
168 local um = require "prosody.core.usermanager"; |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
169 |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
170 local function users(store, host) |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
171 if store.users then |
| 12167 | 172 log("debug", "Using store user iterator") |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
173 return store:users(); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
174 else |
|
12387
05c250fa335a
Spelling: Fix various spelling mistakes (thanks timeless)
Kim Alvefur <zash@zash.se>
parents:
12168
diff
changeset
|
175 log("debug", "Using usermanager user iterator") |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
176 return um.users(host); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
177 end |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
178 end |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
179 |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
180 local function prepare_config(host, conf) |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
181 if conf.type == "internal" then |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
182 sm.olddm.set_data_path(conf.path or prosody.paths.data); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
183 elseif conf.type == "sql" then |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
184 cm.set(host, "sql", conf); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
185 end |
|
13348
47ede3d51833
migrator: Add an escape hatch to allow arbitrary config options
Kim Alvefur <zash@zash.se>
parents:
13142
diff
changeset
|
186 if type(conf.config) == "table" then |
|
47ede3d51833
migrator: Add an escape hatch to allow arbitrary config options
Kim Alvefur <zash@zash.se>
parents:
13142
diff
changeset
|
187 for option, value in pairs(conf.config) do |
|
47ede3d51833
migrator: Add an escape hatch to allow arbitrary config options
Kim Alvefur <zash@zash.se>
parents:
13142
diff
changeset
|
188 cm.set(host, option, value); |
|
47ede3d51833
migrator: Add an escape hatch to allow arbitrary config options
Kim Alvefur <zash@zash.se>
parents:
13142
diff
changeset
|
189 end |
|
47ede3d51833
migrator: Add an escape hatch to allow arbitrary config options
Kim Alvefur <zash@zash.se>
parents:
13142
diff
changeset
|
190 end |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
191 end |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
192 |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
193 local function get_driver(host, conf) |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
194 prepare_config(host, conf); |
|
13920
2169be3581ae
migrator: Allow migrating between different configs of the same driver
Kim Alvefur <zash@zash.se>
parents:
13348
diff
changeset
|
195 mm.unload(host, "storage_" .. conf.type); |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
196 return assert(sm.load_driver(host, conf.type)); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
197 end |
|
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
198 |
|
12164
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
199 local migrate_once = { |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
200 keyval = function(origin, destination, user) |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
201 local data, err = origin:get(user); |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
202 assert(not err, err); |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
203 assert(destination:set(user, data)); |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
204 end; |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
205 archive = function(origin, destination, user) |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
206 local iter, err = origin:find(user); |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
207 assert(iter, err); |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
208 for id, item, when, with in iter do |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
209 assert(destination:append(user, id, item, when, with)); |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
210 end |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
211 end; |
|
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
212 } |
|
12168
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
213 migrate_once.pubsub = function(origin, destination, user, prefix, input_driver, output_driver) |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
214 if not user and prefix == "pubsub_" then return end |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
215 local data, err = origin:get(user); |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
216 assert(not err, err); |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
217 if not data then return end |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
218 assert(destination:set(user, data)); |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
219 if prefix == "pubsub_" then user = nil end |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
220 for node in pairs(data) do |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
221 local pep_origin = assert(input_driver:open(prefix .. node, "archive")); |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
222 local pep_destination = assert(output_driver:open(prefix .. node, "archive")); |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
223 migrate_once.archive(pep_origin, pep_destination, user); |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
224 end |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
225 end |
|
12164
85f03b29ec72
migrator: Refactor out individual item migrator for code deduplication
Kim Alvefur <zash@zash.se>
parents:
12163
diff
changeset
|
226 |
|
12166
39483b4099b4
migrator: Add option to keep going despite errors
Kim Alvefur <zash@zash.se>
parents:
12165
diff
changeset
|
227 if options["keep-going"] then |
|
13142
879a6a33c21b
tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents:
12387
diff
changeset
|
228 local xpcall = require "prosody.util.xpcall".xpcall; |
|
12166
39483b4099b4
migrator: Add option to keep going despite errors
Kim Alvefur <zash@zash.se>
parents:
12165
diff
changeset
|
229 for t, f in pairs(migrate_once) do |
|
12168
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
230 migrate_once[t] = function (origin, destination, user, ...) |
| 12167 | 231 local function log_err(err) |
| 232 if user then | |
| 233 log("error", "Error migrating data for user %q: %s", user, err); | |
| 234 else | |
| 235 log("error", "Error migrating data for host: %s", err); | |
| 236 end | |
| 237 log("debug", "%s", debug.traceback(nil, 2)); | |
| 238 end | |
|
12168
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
239 xpcall(f, log_err, origin, destination, user, ...); |
|
12166
39483b4099b4
migrator: Add option to keep going despite errors
Kim Alvefur <zash@zash.se>
parents:
12165
diff
changeset
|
240 end |
|
39483b4099b4
migrator: Add option to keep going despite errors
Kim Alvefur <zash@zash.se>
parents:
12165
diff
changeset
|
241 end |
|
39483b4099b4
migrator: Add option to keep going despite errors
Kim Alvefur <zash@zash.se>
parents:
12165
diff
changeset
|
242 end |
|
39483b4099b4
migrator: Add option to keep going despite errors
Kim Alvefur <zash@zash.se>
parents:
12165
diff
changeset
|
243 |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
244 local migration_runner = async.runner(function (job) |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
245 for host, stores in pairs(job.input.hosts) do |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
246 prosody.hosts[host] = startup.make_host(host); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
247 sm.initialize_host(host); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
248 um.initialize_host(host); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
249 |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
250 local input_driver = get_driver(host, job.input); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
251 |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
252 local output_driver = get_driver(host, job.output); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
253 |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
254 for _, store in ipairs(stores) do |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
255 local p, typ = store:match("()%-(%w+)$"); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
256 if typ then store = store:sub(1, p-1); else typ = "keyval"; end |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
257 log("info", "Migrating host %s store %s (%s)", host, store, typ); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
258 |
|
12168
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
259 local migrate = assert(migrate_once[typ], "Unknown store type: "..typ); |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
260 |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
261 local prefix = store .. "_"; |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
262 if typ == "pubsub" then typ = "keyval"; end |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
263 if store == "pubsub_nodes" then prefix = "pubsub_"; end |
|
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
264 |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
265 local origin = assert(input_driver:open(store, typ)); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
266 local destination = assert(output_driver:open(store, typ)); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
267 |
|
12168
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
268 migrate(origin, destination, nil, prefix, input_driver, output_driver); -- host data |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
269 |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
270 for user in users(origin, host) do |
| 12167 | 271 log("info", "Migrating user %s@%s store %s (%s)", user, host, store, typ); |
|
12168
33e856c65033
migrator: Support pubsub and pep as a special-case
Kim Alvefur <zash@zash.se>
parents:
12167
diff
changeset
|
272 migrate(origin, destination, user, prefix, input_driver, output_driver); |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
273 end |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
274 end |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
275 end |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
276 end, watchers); |
|
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
277 |
|
4240
b3d9063aad4d
tools/migration/prosody-migrator.lua: Add messages to show when migration is in progress
Matthew Wild <mwild1@gmail.com>
parents:
4239
diff
changeset
|
278 io.stderr:write("Migrating...\n"); |
|
10003
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
279 |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
280 migration_runner:run({ input = config[from_store], output = config[to_store] }); |
|
4d702f0c6273
migrator: Rewrite to use storage modules
Kim Alvefur <zash@zash.se>
parents:
8062
diff
changeset
|
281 |
|
4240
b3d9063aad4d
tools/migration/prosody-migrator.lua: Add messages to show when migration is in progress
Matthew Wild <mwild1@gmail.com>
parents:
4239
diff
changeset
|
282 io.stderr:write("Done!\n"); |
