Skip to content

One-shot migration

A one-shot migration moves each domain to Stalwart in a single step. Vandelay first creates every account on Stalwart and copies it while users keep working on the source, and keeps the copies current with delta passes. The operator then changes the domain’s MX records and client settings to Stalwart, confirms the change in Vandelay, and a final pass copies what reached the source until then. From the MX change onwards, all mail of the domain is delivered to Stalwart and its users sign in there.

This is the strategy for every source that the Stalwart proxy cannot sit in front of, which includes the hosted services Microsoft 365 and Google Workspace, whose network and ports the operator does not control. It also suits a self-hosted source when a short change window is acceptable and running a proxy is not worth the effort. There is no per-account switch and no split delivery: until the MX change all mail goes to the source, and after it all mail goes to Stalwart. In Vandelay, it is the cutover strategy “Whole domains by MX change” (cutover.mode = "domain").

A domain moves through these stages, which the “Cutover: domain checklist” screen and vandelay migrate cutover-check follow:

  1. Copy. vandelay migrate run provisions the domains, accounts, aliases, groups, lists and DKIM keys on Stalwart, then copies every selected account. Users keep working on the source, so nothing they see changes.
  2. Keep current. Delta passes copy what changed on the source since the previous pass. The “Delta passes” setting (cutover.deltas) runs them at an interval, such as 6h, or leaves them to the operator (manual).
  3. Sweep. Shortly before the planned change, a delta sweep of the domain brings every account up to date, so that the final pass only has to copy the last minutes. The checklist schedules it ahead of the change by the “Delta sweep lead time” (cutover.sweep_lead), or it is started by hand with vandelay migrate delta --sweep --domain example.org.
  4. Change the MX records of the domain to Stalwart, together with the client records described below.
  5. Confirm the change in Vandelay. The final pass and the switch of every account of the domain start at once: a create-only copy of what reached the source since the last delta pass, followed by verification.

The checklist lists each account with its last delta. An account whose last completed delta is older than the “Stale delta after” setting (cutover.max_delta_age) is flagged, because flag and folder changes made on the source after that delta are not carried: the final pass only creates new messages. An account that never completed a delta blocks the confirmation with domain <domain>: accounts <ids> never completed a delta.

The MX change moves inbound mail. Clients follow only when their settings point at Stalwart too, and Vandelay does not check these records, so they are changed in the same window:

  • MX records of the domain, to Stalwart’s mail exchanger. Lowering their TTL to 300 seconds at least a day before the change, which the checklist lists as its first item, makes sending servers pick the change up quickly.
  • Client server names. When users reach the old server under a name of the domain, such as mail.example.org, repointing that name to Stalwart moves every client configured with it. Clients set up with a provider’s own account type, as is common with Microsoft 365 and Google Workspace, keep connecting to the provider and must be set up again.
  • Autoconfig, Autodiscover and SRV records, pointed at Stalwart, so that clients set up after the change find it.
  • SPF, DKIM, DMARC and MTA-STS, so that Stalwart’s outgoing mail is accepted. DKIM keys generated by provisioning are published before the change; imported keys keep their records. DNS records describes what Stalwart needs.

Stalwart needs a certificate for every public name that moves to it, issued before the change through ACME or installed manually. An HTTP-01 or TLS-ALPN-01 challenge for a name that still resolves to the source fails, so names that move only at the change use the DNS-01 challenge.

The MX change is confirmed per domain, once the new records are published. From the checklist screen, “Confirm the MX change” with the domain’s name; on the command line:

Terminal window
vandelay migrate cutover-check --domain example.org
vandelay migrate cutover-check --confirm-mx --domain example.org

The first command prints the checklist. The second asks for confirmation, by typing the number of accounts on a terminal or by passing back the --confirm N:TOKEN it prints when run without one, because Vandelay cannot undo the MX change once it is confirmed. The final pass and the verification then run for every account of the domain, and the accounts move to Switched.

Mail that reaches the source after the final pass, from senders whose resolvers still cache the old MX records, is copied by catch-up passes. The “Catch-up passes after the switch” setting (cutover.catch_up) runs them at an interval, such as 1d, until the account is closed with Complete. Like the final pass, a catch-up only creates new items: a message the user deleted permanently on Stalwart reappears when it is copied again, and later flag changes on the source do not follow.

Users are not cut off at any point, but they work on two servers for a while. Until their client follows the new records, it keeps using the source, and changes made there after the final pass are carried only by the catch-up passes. Clients that follow the change see their mailbox as new data: Stalwart assigns its own identifiers, so IMAP clients download the folders again, CalDAV, CardDAV and WebDAV clients synchronise their collections again, and every message carries one of the keywords $hasattachment and $hasnoattachment, which Stalwart sets from the message’s content.

A short window, in which users are asked not to work and the old server’s client access is closed right after the MX change, keeps the gap small. The source stays readable for the catch-up passes until it is decommissioned.

When every account of every domain is switched and verified, Finish sets the catch-all addresses and removes the allowed-IP entry that Vandelay created for its host. Deleting the archives of completed accounts and wiping the project’s secret store cannot be undone, so they run only when ticked, or named with --only archives,vault. After Finish the runner stops and the project is read-only, as described in Finishing a project. Raise the TTLs lowered for the change, and decommission the source once Stalwart has run on its own for long enough to be trusted.