sync mails with dovecot over tcp 7


I use on my servers ISPConfig, for IMAP and POP3 Dovecot is used. With Dovecot 2.x, the mails can also keep in sync between two servers. The replication is done via the Dovecot index files. So neither an error in the file system nor an accidentally deleted Maildir have a negative effect.

Here I describe the installation of Dovecot 2.x on Debian Wheezy. The synchronization is done via TCP (though ssh is also possible, but TCP is set up with less effort). For other operating systems a list of repositores /steps is available here.
echo "deb http://xi.rename-it.nl/debian/ stable-auto/dovecot-2.2 main" >> /etc/apt/sources.list

wget -O - http://xi.rename-it.nl/debian/archive.key | apt-key add -

apt-get update
apt-get upgrade

You can test the installed version of Dovecot with
dovecot --version

In the next step Dovecot needs to know the mail user for which the mails should be synchronized. Open /etc/dovecot/dovecot-sql.conf and activate the iterate_query:

iterate_query = SELECT email as user FROM mail_user

Various entries are to be made in the config for the synchronization. The following extensions must be added to /etc/dovecot/dovecot.conf.

# Enable the replication plugin globally
mail_plugins = $mail_plugins notify replication

# The mail processes need to have access to the replication-notify fifo and socket.
service aggregator {
  fifo_listener replication-notify-fifo {
    user = vmail
    mode = 0666
  }
  unix_listener replication-notify {
    user = vmail
    mode = 0666
  }
}

# Enable doveadm replicator commands
service replicator {
  unix_listener replicator-doveadm {
    mode = 0666
  }
}

# Create a listener for doveadm-server
service doveadm {
  user = vmail
  inet_listener {
    port = 12345
  }
}

# configure how many dsyncs can be run in parallel (10 by default)
replication_max_conns = 10

# tell doveadm client to use this port by default
doveadm_port = 12345

#Both the client and the server also need to have a shared secret
doveadm_password = secret

# use tcp:hostname as the dsync target
plugin {
  mail_replica = tcp:anotherhost.example.com # use doveadm_port
  #mail_replica = tcp:anotherhost.example.com:12345 # use port 12345 explicitly
}

service config {
  unix_listener config {
    user = vmail
  }
}

After that restart dovecot.
/etc/init.d/dovecot restart

A few hints / tips for synchronization:

Output of state of replication:

doveadm replicator status

Show users in the replication:

doveadm replicator status '*'

Start the replication for all mailboxes manually:

doveadm sync -A

tcp:anotherhost.example.com

Start the replication of only one mailbox manually:

doveadm sync -u

user@example.com tcp:anotherhost.example.com

Sieve-File
The Sieve file should not be below the Maildir directory if it starts with a dot. In ISPConfig .sieve is already outside the Maildirs – changes are not required.


Leave a comment

Your email address will not be published. Required fields are marked *

I confirm

7 thoughts on “sync mails with dovecot over tcp

  • Jorge Canto

    Hello Florian, I just set up the replication between 2 servers following the steps on this tutorial and everything worked fine, those servers are running Dovecot 2.2.10; now I want to set up the replication between other 2 servers following the same steps but now the difference is that one of those servers is running dovecot 2.2.10 (Server B) and the other one is running 2.2.32 BUT on this server (Server A) the dovecot version was updated from 2.0.9 to 2.2.32, Server A has been working for almost 4 years (so it is not a new configuration) but I had to update dovecot to be able to replicate to Server B, I do not want to replicate every user from Server A to Server B so I set iterate_query to select only the users I want, but for some reason the replica service tries to replicate every user in the database, the weird thing is, on my dovecot-sql.conf.ext file I removed the iterate_query and the replication is still looking up users so it means (I think) the replicator service is reading the database from somewhere else and I would like to know where from, If I run the command “doveadm user ‘*’ ” I receive an error (obviuosly) ’cause there is not iterate_query set, but on the maillog file I can see replications tries to Server B, Do you have any suggestion?

    Thank you so much

    Jorge C.

  • Michael

    Hi Florian,

    danke für das HowTo.
    Die manuelle Synchronisation läuft problemlos.
    Allerdings synchronisieren meine beiden Server nur, wenn ich manuell den Befehl

    doveadm replicator replicate ‘*’

    eingebe.
    hast Du eine Idee, woran das liegen könnte?
    Mein Listing entspricht genau Deinem Listing (außer, dass ich andere Server und Passwörter benutze).

    Gruß, Michael

  • Micha

    Hallo Florian,

    eines ist mir nicht ganz klar: muss ich auf beiden Servern die dovecot.conf ändern? Und dann als mail_replica-Host jeweils
    den anderen eintragen?

    Trotzdem schon mal jetzt Danke fürs Teilen deiner Infos,

    Micha

  • wynni

    Hallo Florian,

    habe deine Anleitung erfolgreich nachbauen können. Vielen Dank dafür.
    Ich habe nur noch eine Frage:
    Wie sieht es mit den sync Zeiten aus. Wann wird ein fast sync bzw. full sync durchgeführt?

    Danke

    wynni