use dovecot to replicate your mails

Discussion in 'Tips/Tricks/Mods' started by florian030, Jul 2, 2014.

  1. florian030

    florian030 Well-Known Member HowtoForge Supporter

    With dovecot 2.x you can sync your mails over tcp (or ssh) between two servers.

    Just install the latest dovecot-version.

    Comment-out the iterate_query from /etc/dovecot/dovecot-sql.conf:
    Code:
    iterate_query = SELECT email as user FROM mail_user
    And add the settings for the replication dovecot.conf:

    Code:
    # 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
      }
    }
    Afterwards dovecot keeps your mails in sync between two servers. You can also create backups (no replication) with doveadm.

    You may find additional infos here.
     
  2. Hi Florian
    Last weekend i was migrating a standalone ISPConfig 3.1.1p&Ubuntu 14.04 made by PerfectServer Tutorial to a newone using Ubuntu 16.04 and ISPConfig 3.1.11...i've made a backup from /var/vmail & /var/www & etc and moved to the new one ....once it not worked i am still using the old server to dovecot/postfix mailboxes and Wordpress Websites....
    Since yestarday i am analyzing what was wrong and i can stop the old email services once i have a few mailboxes exchanging messages regularly and remotely...So i would like to be sure that your suggestion just above can syncronize two dovecot/postfix servers indeed in such way that i can run both in the both servers and once i get the new one really working and confirmed...i would descontinue the old one and just keep the one without running on risk of lost any message?
    ------------------------------------------------------------------------------------------------------------
    In the production(old 14.04) what should i use at this piece of script?
    # 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
    }
    ------------------------------------------------------------------------------------------------------------
    In the new production(16.04) what should i use at this piece of script?
    # 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
    }
    ------------------------------------------------------------------------------------------------------------
    Which "technical" guarantee that i can expect that the syncronize will make the new production server that has a backup from last weekend will get the newest messages since that weekend and the old one will not have the messages from the last weekend until now deleted when syncronized to the new one?
     
  3. and BTW I prefer sync mailboxes by ssh, how to do this?
     
  4. gody

    gody Member

    Hello,

    I use the dovecot repplication on another setup but the iterate query work only when you reload the dovecot ... So i create a plugin for ispconfig ...

    You have several tools to do this.
    Perso I use imap_tools (athensfbc.com) for a one way sync. You have several perl script for different task.
    Actually the website is down... but i'm sure you can found something else.
     
  5. florian030

    florian030 Well-Known Member HowtoForge Supporter

    i would start with an empty server (no mails in /var/vmail - just all folders). if you start the dovecot-replication, the 2nd server will receive all mails.

    i have some problems with the itate_query "WHERE `disable%Ls` = 'n'" - this is still working on my servers so i removed this part. But with a replication it makes no sence to exclude inactive users from the replication.
     
  6. OK.. many thanks....i've took the decision to TAR vmail folders contents with the -N "2018-01-23 14:00:00" and uncompressed it in the destination server a few minutes before put the new one as production server....
     
  7. BlackRaven

    BlackRaven New Member

    Thanks for this small tutorial - but I must admit I have some questions:
    • Should the mailboxes/users be already defined on both sides?
    • Could I limit the synchronisation to just one domain?
     

Share This Page