Migration recovery guidance required — Stalwart v1 started before run --final

Issue Description

Migration recovery guidance required — Stalwart v1 started before run --final

Expected Behavior

We are migrating an independent production Stalwart deployment from v0.16.27 to v1.0.0 using the official stalwart-migrate tool.

Source

Stalwart v0.16.27

PostgreSQL 17.11

Source remains healthy and in production.

Source IP: 10.10.50.1 (old server)

Target

Stalwart v1.0.0

PostgreSQL 17

Target IP: 10.10.50.2 (New server)

Target database: stalwart

Migration history

prepare completed.

Three ordinary incremental run attempts were recorded.

Run #3 was intentionally interrupted using SIGINT. The tool logged a graceful shutdown and reported status: interrupted, with zero migration errors.

The target Stalwart v1 container was started after Run #3.

The final run --final has never been executed.

The target v1 service has been running, performing background operations against its PostgreSQL database.

No SMTP, IMAP, JMAP, or authentication traffic has been observed on the target.

HAProxy still directs production traffic to the original v0.16.27 server.

Migration state

Tool version: 1.0.0

Tracked accounts: 578

Done phase: 549

Full phase: 26

Container phase: 3

Failed accounts: none

Run #3: 982,433 objects written, 977,163 emails written, 840,694 blobs copied, zero reported errors.

No final-report.txt exists.

Questions requiring your guidance

Is it supported to stop the target v1 service and resume the existing migration state with an ordinary incremental run, followed by run --final after stopping all v0.16 nodes?

Can background writes made by v1 before finalization cause conflicts, unexpected data, or verification mismatches?

Should we instead create a new empty target PostgreSQL database and a fresh migration state, then repeat the migration from the unchanged source?

Is there a documented recovery procedure for this exact situation?

Are there any specific precautions regarding PostgreSQL data, blob storage, or migration state before proceeding?

We will preserve the original v0.16 production server and will not use --force-after-final, rollback, or destructive target operations without your confirmation.

We would appreciate a documented, supported recovery recommendation.

Stalwart Version

v1.x

Installation Method

Docker

Database Backend

PostgreSQL

Blob Storage

PostgreSQL

Search Engine

Internal

Directory Backend

LDAP

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

Path glob probably needs a different form.

Resuming is supported by the docs, but the docs don’t describe your exact case, which is v1 started on the target before the first run --final. A human will need to confirm the parts below that I mark as uncertain.

What the docs support

  • Interrupted runs are resumable. The tool records progress only after the matching write to the target has been committed, and it writes with the original identifiers. Repeating a batch overwrites identical data and doesn’t create duplicates. After an interrupt, the same command with the same state directory resumes from the last recorded position, and status shows the run as interrupted. A SIGINT stop with zero errors is a normal, safe case.
  • The tool treats “1.0 started on the target” as a state that matters only after the final run has completed. The --force-after-final guard exists for that case, and your migration never reached it. You don’t need that flag, so don’t use it.
  • The documented sequence is to repeat incremental runs as needed, stop every 0.16 node, then run run --final. Finalising recalculates quotas, schedules calendar alarms, queues every copied object for search indexing, and records DAV changes. It then verifies a sample of accounts and marks the migration done.

What the docs don’t cover
The docs don’t say whether a 1.0 server that ran against the target before finalising leaves anything that conflicts with the migration. That includes its background work such as housekeeping, task scheduling, and possibly indexing or quota tasks on the copied data.

The docs also say a verification mismatch that no earlier report explains always blocks finalisation. They describe that case as the target holding something other than what the copy wrote and reported. Background writes by v1 could in principle cause such a mismatch, but I can’t confirm that from the docs. I also can’t say whether the tool would then fail cleanly, and --allow-errors doesn’t cover mismatches.

Practical recommendation

  1. Stop the v1 container on the target now, so that nothing else writes to the database.
  2. Take a PostgreSQL backup of the stalwart database and a copy of the state directory (/var/lib/stalwart-migrate or wherever yours is). This gives you a way back whatever happens next. The source is untouched, since the migration never writes to the 0.16 store.
  3. Run the same incremental run command again with the same state, and check stalwart-migrate status.
  4. In the maintenance window, stop every 0.16 node and run run --final. Consider --verify-full to compare everything rather than a sample, since v1 has already touched the target. Then review final-report.txt.
  5. If the final run reports unexplained verification mismatches, don’t force it with --allow-errors. Stop and ask here. At that point, creating a new empty database and a fresh state directory and repeating the migration from the unchanged source is the clean fallback. The docs say the target must be a new, empty store, and the source is unchanged, so this is safe. It costs a full recopy.

If you’d rather not depend on an unverified assumption, the fresh-database route is the conservative choice. Your source is healthy and the copy only reads from it. A staff member should confirm whether the resume path is safe for your case.

References:

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

Thank you for the detailed explanation and recommendations.

We understand that interrupted migration runs are resumable under normal circumstances, but our situation is different because Stalwart v1.0.0 was started against the partially migrated target before the first run --final was executed.

Before proceeding, we would appreciate explicit confirmation from the Stalwart engineering team on the following points.

1. Existing migration state and target compatibility

  • Is it technically safe to stop the v1 service and resume the existing migration using the same state directory?

  • Can v1 background operations (housekeeping, quota recalculation, indexing, calendar scheduling, DAV changes, etc.) modify records that the migration utility expects to control?

  • Could these operations cause verification mismatches or unexpected data changes during subsequent incremental runs or run --final?

  • Is there a supported way to inspect the existing target for compatibility with the migration state without modifying it?

2. Recovery recommendation

We are considering two possible approaches:

Option A: Stop v1, preserve the existing target and migration state, resume with ordinary incremental run, and execute run --final after stopping all v0.16 nodes.

Option B: Preserve the existing target for investigation, create a completely new empty PostgreSQL database and isolated blob storage, initialize a fresh migration state, and repeat the migration from the unchanged v0.16.27 source.

Which approach does the engineering team officially recommend for our specific situation?

3. Fresh migration preparation

If Option B is recommended, please confirm:

  • Whether the existing answers.toml can be reused or must be reviewed and regenerated.

  • Whether a completely new state directory is mandatory.

  • Whether the new target requires completely separate blob storage.

  • Whether any cleanup or special handling is necessary for the previous migration artifacts.

4. Verification and finalization

If Option A is considered safe, please clarify whether run --verify-full is sufficient to detect inconsistencies introduced by the early v1 startup, and whether any additional checks are recommended before finalization.

Our current environment and safeguards:

  • Source: Stalwart v0.16.27, PostgreSQL 17.11, 10.10.50.1.

  • Target: Stalwart v1.0.0, PostgreSQL 17, 10.10.50.2.

  • Three incremental runs were recorded.

  • Run #3 was interrupted gracefully using SIGINT, with zero reported errors.

  • The target v1 service was started after Run #3.

  • No SMTP, IMAP, JMAP, or authentication traffic reached the target.

  • Production traffic continues to use the original v0.16.27 server through HAProxy.

  • run --final has never been executed.

  • The original production source remains healthy and unchanged.

We are not planning to use --force-after-final, bypass verification, or perform destructive operations on the existing target.

Our priority is to complete this migration with data integrity and a reliable rollback path. We are willing to perform a complete migration again using a fresh target if that is the only approach the engineering team can confidently support.

Could you please escalate this case to a Stalwart migration engineer or developer familiar with the internal behavior of stalwart-migrate v1.0.0 and provide a specific recovery recommendation for this sequence of events?

Thank you for your assistance.

Hi Riad,

I’d go with Option B: a new empty PostgreSQL database and a new state directory, copied again from the untouched 0.16.27 source.

stalwart-migrate assumes it’s the only writer on the target until run --final has completed. Once 1.0 boots it starts its own background work (task processing, housekeeping and purges, indexing), and nothing guarantees that leaves the target exactly as the tool wrote it. An incremental run copies only what changed on the 0.16 side since the previous run, so anything 1.0 changed or removed on the target is not put back. run --final --verify-full (or verify --full once 0.16 is stopped) would most likely flag such differences as mismatches, but it can’t repair them, and finding one on the night of the cutover means starting over anyway. Since 0.16 is still serving users and the source hasn’t been touched, a fresh copy costs you time and nothing else, and it ends with a target the tool fully vouches for. There’s no documented procedure for this situation; this is the one I’d trust.

For the new copy:

  1. Keep the 1.0 container stopped, and make sure it can’t reach the new database until the final run has completed.
  2. Create a new empty database and point a copy of the target configuration at it. Your blobs live in PostgreSQL, so there is no separate blob storage to set up.
  3. Use a new state directory. The tool records a fingerprint of the source and target definitions in it and refuses to continue with a different target, so the old one can’t be reused.
  4. Copy answers.toml from the old state directory into the new one and run prepare --non-interactive with the new --target. It validates the existing answers and writes a fresh prepare-report.txt, so you don’t have to answer everything again unless it raises a new question.
  5. Run the incremental runs as before, then stop every 0.16 node, run run --final (add --verify-full if you want every account checked) and start 1.0 only after it completes.

Nothing needs cleaning up from the earlier attempt. The old database and state directory aren’t touched by the new migration, so you can keep them for investigation and drop them once you’ve switched over. Don’t run anything from the new migration against the old state directory, or the other way round.

Preparing the migration | Stalwart covers the state directory and answers.toml, and Running the migration | Stalwart the final run.