Repair a Broken Dovecot Mailbox with doveadm force-resync
One user's mailbox has stopped behaving, and Dovecot cannot fix it on its own, so doveadm force-resync is the repair tool. This guide runs it against one named user and mailbox in 10 to 20 minutes, then shows you how to check the result.
The route
Jump straight to the step you need, or tick off Done means at the end.
It follows the installed dovecot-core package, version 1:2.3.21+dfsg1-2ubuntu6.5, and its Dovecot 2.3 manpage. You need shell access to the mail host, the doveadm command, and enough permission to use Dovecot's administrative socket. Allow more time if you need a backup or a second check.
Warning
The command repairs mailbox state. Schedule it in a quiet period and make sure your normal mail backup is current first.
1. Confirm the installed command
Check which binary will run and record the package version before touching a mailbox:
$ command -v doveadm
/usr/bin/doveadm
$ dpkg-query -W -f='${Package} ${Version}\n' dovecot-core
dovecot-core 1:2.3.21+dfsg1-2ubuntu6.5
The installed manual describes doveadm force-resync as a repair command for cases where Dovecot cannot solve mailbox problems automatically. For sdbox and mdbox storage it also checks the storage files. It is not a general-purpose index rebuild, and it is not a harmless status query.
Checkpoint
If command -v finds a different installation, stop and read that installation's documentation. The syntax and storage behaviour below are tied to the local 2.3 package.
2. Choose one exact mailbox
Start with one user and one mailbox. The documented example uses the Inbox:
$ sudo doveadm force-resync -u '[email protected]' INBOX
- Use the exact user. Replace
[email protected]with the user known to Dovecot. The-uoption also accepts a mask with*and?, but do not use a wildcard while you are still diagnosing one broken account. INBOXis a real name. It is not a placeholder. Substitute another name such asArchiveonly when that is the mailbox that needs repair.sudois optional. It is shown because mailbox administration commonly needs elevated access, but the syntax does not require it. Use the least privilege your Dovecot configuration permits. If your operator account can already reach the administrative socket, omit it.
The command may print nothing useful on success. Check the exit status immediately:
$ status=$?
$ printf 'force-resync exit status: %s\n' "$status"
force-resync exit status: 0
A zero status means the command completed successfully. It does not mean the mailbox had no earlier damage, and it does not replace an application-level check such as opening the mailbox through IMAP.
3. Protect the repair window
force-resync attempts to fix mailbox problems and can update mailbox storage. Before running it on a valuable account, confirm that no migration, restore, mail delivery repair or concurrent mailbox conversion is in progress. Keep the original backup and any incident evidence until the user has verified the result.
Recovery
This operation has no universal undo command. If it makes a problem worse, restore from a known-good backup or use your documented Dovecot recovery procedure.
Warning
Do not delete mailbox files to make the command succeed. That is an irreversible escalation, not a repair step.
Checkpoint
Write down the target user, mailbox, start time and exit status. If you cannot identify those four items, do not widen the scope.
4. Add diagnostics only when needed
Use -v for verbosity and a progress counter:
$ sudo doveadm -v force-resync -u '[email protected]' INBOX
Use -D when you need debug messages while investigating a failure:
$ sudo doveadm -Dv force-resync -u '[email protected]' INBOX
These options report more detail. They do not change the target mailbox or make an invalid user valid. Capture the output in your incident record, but check it does not expose mailbox names or other operational data before sharing it outside the mail team.
If the command cannot connect to the expected Dovecot administrative socket, -S can select one explicitly. Its argument is either an absolute local UNIX socket path or a remote hostname:port:
$ sudo doveadm -S /path/to/doveadm.socket force-resync -u '[email protected]' INBOX
$ sudo doveadm -S mail-admin.example.org:12345 force-resync -u '[email protected]' INBOX
Warning
Use a remote socket only when it is already part of your secured Dovecot design. Do not expose a management socket to the network just to make this command convenient.
5. Repair a controlled list of users
Once the single-user command is understood, -F can read one username per line from a file:
$ umask 077
$ printf '%s\n' '[email protected]' '[email protected]' > /tmp/dovecot-resync-users
$ sudo doveadm force-resync -F /tmp/dovecot-resync-users INBOX
$ rm -- /tmp/dovecot-resync-users
Review the file before running the repair. It holds account names, so the restrictive umask and prompt removal matter. If the command fails, keep a copy of the exact input list in your incident records instead of rebuilding a bigger list from memory.
Warning
-A runs the command for all users returned by the user database. The local manpage specifically warns against combining it with system users from userdb { driver = passwd }, because that can include users below first_valid_uid. For SQL, verify that iterate_query matches the database layout. For LDAP, verify iterate_attrs and iterate_filter. A broken iteration definition can omit users or target the wrong set.
$ sudo doveadm force-resync -A INBOX
Use this only as an intentional fleet operation, with a maintenance plan, monitoring and a tested recovery route. A targeted -F list is easier to review and stop.
6. Diagnose a failed repair
First preserve the exit status and the diagnostic output. Then check the user, mailbox spelling, Dovecot configuration and socket access. A useful configuration snapshot is:
$ sudo doveconf -n
Compare the configured user database, mailbox location and storage driver with the account you targeted. The Dovecot manpage recommends including this output when reporting a bug to the Dovecot mailing list.
Warning
Do not paste doveconf -n into a public ticket without reviewing it for hostnames, paths and account details.
If a repair fails because the service is busy, coordinate with the mail service owner before stopping anything. Restarting Dovecot or editing storage files is outside this command and can create a second failure. If the mailbox is still inaccessible after a zero status, test the account through the normal client path and inspect Dovecot's service logs before repeating the repair.
Done means
- Command confirmed. The installed
doveadmanddovecot-coreversions are recorded. - Scope pinned. The first repair targeted one exact user and mailbox with
-u. - Evidence kept. The exit status and any diagnostic output were recorded.
- Boundaries checked. Backup, concurrency and recovery were checked before changing mailbox state.
- Wide options earned.
-For-Awas used only after reviewing the user scope and iteration configuration. - User verified. The user confirmed mailbox access after the repair, and the original recovery evidence remains available.