Dovecot doveadm-sync dsync

Is it possible to setup automatic mail sync between two Hestia servers?
I have 2 Debian 12 Hestia 1.9.3 installs.
Tried to setup Dovecot sync with official guides.

adding 20-dsync.conf

doveadm_password = superuserpassword

replication_max_conns = 10

service aggregator {
    fifo_listener replication-notify-fifo {
        group = mail
        user = admin
        mode = 0660
    }
    unix_listener replication-notify {
        group = mail
        user = admin
        mode = 0660
    }
}

service replicator {
    process_min_avail = 1
    unix_listener replicator-doveadm {
        mode = 0660
        user = admin
        group = mail
    }
}

service doveadm {
        user = admin
        group = mail
    inet_listener {
        port = 12345
        ssl = yes
    }
}

plugin {
    mail_replica = tcps:mail2.server.com:12345
    replication_sync_timeout = 2
}

It works when I run command from root

doveadm -v sync -u [email protected] tcps:mail2.server.com:12345

using script

#!/bin/bash
# getting list of domains
DOMAINS=$(ls /etc/exim4/domains/)
SERVER=mail2.server.com
PORT=12345

for domain in $DOMAINS; do
    # getting users from passwd file
    USERS=$(cut -d: -f1 /etc/exim4/domains/$domain/passwd)

    for user in $USERS; do                                                                                                                                          
        doveadm -v sync -u $user@$domain tcps:$SERVER:$PORT
    done
done

But it doesn’t work as it should - automatically without any scripts in cron.
When I send or receive letters from to server1 nothing happens.

After start dovecot writes errors in syslog:

May 15 05:33:56 auth-worker(300404): Error: conn unix:auth-worker (pid=300403,uid=107): auth-worker<1>: passwd-file(*): passwd-file: User iteration isn't currently supported with %variable paths
May 15 05:33:56 replicator: Error: auth-master: userdb list: User listing returned failure
May 15 05:33:56 replicator: Error: listing users failed, can't replicate existing data

As far as i see it can’t get users list because config uses %v variable in path of passwd files for domains.

I’ve added all users to doveadm replicator using same script as above

for domain in $DOMAINS; do
    USERS=$(cut -d: -f1 /etc/exim4/domains/$domain/passwd)
    for user in $USERS; do                                                                                                                                          
        doveadm replicator add $user@$domain
    done
done

dovecot/replicator is running

doveadm replicator status

Queued 'sync' requests        0
Queued 'high' requests        0
Queued 'low' requests         0
Queued 'failed' requests      0
Queued 'full resync' requests 451
Waiting 'failed' requests     7
Total number of known users   458

Another problem that is HOME set to /home/admin and doveadm trying to use this folder for creating lock files while syncing and that give an error:

May 15 06:01:58 doveadm([email protected])<304589><dZERLCNnJWjNpQQA8knpeQ>: Error: Couldn't lock /home/admin/.dovecot-sync.lock: fcntl(/home/admin/.dovecot-sync.lock, write-lock, F_SETLKW) locking failed: Interrupted system call

Cause this file is trying to lock for several sync processes at a time.
But it should be created at each users folder separatly.

WTF… Just visited Dovecot site and found that they removed replicator from stable 2.4.0 release.

 replicator: Feature has been removed. Use NFS or some other shared
	  filesystem instead, or run doveadm sync in crontab.

I’m confused.. Now we have 2.3.19 in Debian 12. So it doesn’t have sense to setting it up at the moment.. :frowning:

Imapsync might be able to do it …

1 Like

Yeah, i used it migrate users from server to server and it’s very good for it, but I need a tool to fast automatic changes sync between two servers to build a cluster. Internal replicator service integrated to dovecot was a perfect solution..

Ended up setting shared NFS storage on main mail server.

Wrote scripts syncing /home/admin/conf via rsync and changing ips from mail configs for according Hestia server (/home/admin/conf/mail/DOMAIN/ip - should match external ip of exim4 server, in other way exim4 wouldn’t send mail and give error that can’t bind address).

/etc/exim4/domains/* and /etc/dovecot/conf.d/domains/* should 100% repeat main server.

Each server can send mail, has own exnternal IP and PTR record, mail received to main mail server with shared NFS storage.

So everything is working. But the idea was to build independent server with own storage :frowning:

Testing this for 1 day and ready to say that NFS is pretty slow. Thow iperf3 shows 200mbit\s between them wrapped with Wireguard.
Everybody says to try GlusterFS.
Going to test it. :slight_smile: