[Dovecot] Dovecot dsync mail replication issues

2012-04-30 Thread Reuben Farrelly

Hi,

I'm trying to set up some dsync based replication between two hosts on 
my network.  The current topology is a single server running Postfix 
with a single dovecot installation with a Maildir per user (only 4 users 
including myself).  No NFS, just local system users on ext4.  I am only 
using system users, ie no virtual users.  I am using dovecot deliver to 
deliver mails into the Maildir's.  This - being a very standard Maildir 
installation -  all works just fine.


I'm running dovecot-2.1.5 (release versions) x86_64 with Gentoo on both 
hosts and using key based ssh to transport the data using the root login.


What I would like to do is extend the design so as to replicate the 
Maildirs across a second machine and in the future be able to connect 
via IMAP into either machine to sync mail.  Two way dsync would be 
rather cool because I could then deliver via SMTP to either system and 
have changes automagically propagate - but initially just simple 
replication would be a good start.


I was hoping that dsync would allow me to do this, but I've run into 
quite a number of problems while getting this to work.


http://dovecot.org/list/dovecot/2012-March/064243.html
...was very useful and I've based my config on that.

Initially I've tried to sync up the user Maildirs, and this has more or 
less worked:


doveadm sync -u lyn remote:r...@dustbowl.reub.net

This succeeds without error on the initial sync.

However if I try to run the re-sync again (such as a use case of if the 
sync of another Maildir takes 4 hours so I want to resync up the earlier 
ones again) I end up with a mysteriously named INBOX folder in both the 
source and destination Maildirs:


drwx--  5 lyn lyn  4096 Apr 30 19:32 
.INBOX_7a86a62d465a974fb92f3b258734


It has the basic structure of a Maildir but is empty in terms of mails:

drwx--  2 lyn lyn 4096 Apr 30 19:32 cur
-rw---  1 lyn lyn  220 Apr 30 19:32 dovecot.index.log
-rw---  1 lyn lyn   51 Apr 30 19:32 dovecot-uidlist
-rw---  1 lyn lyn0 Apr 30 19:32 maildirfolder
drwx--  2 lyn lyn 4096 Apr 30 19:32 new
drwx--  2 lyn lyn 4096 Apr 30 19:32 tmp

First question:  why is this random named directory being created in the 
origin Maildir?  Shouldn't the replication be more or less read-only in 
the origin Maildir?


Second question:  If I re-attempt a doveadm sync a second time I get 
this error:


tornado Maildir # doveadm sync -u lyn remote:r...@dustbowl.reub.net
dsync-local(lyn): Error: Can't rename mailbox 
INBOX_7a86a62d465a974fb92f3b258734 to INBOX: Target mailbox already 
exists
dsync-local(lyn): Error: Can't rename mailbox INBOX to 
INBOX_eb15f30ea563be4b70322bd68bb1: Renaming INBOX isn't supported.

tornado Maildir #

It's not clear if the second attempt has failed or succeeded, and it's a 
bit odd that it errors out on a directory that the dovecot sync process 
itself has created.


Third question:  Upon starting Dovecot lots of ugliness is logged in the 
mail log:


Apr 30 19:44:59 tornado dovecot: master: Dovecot v2.1.5 starting up 
(core dumps disabled)
Apr 30 19:44:59 tornado dovecot: doveadm(mozsync): Error: user mozsync: 
Initialization failed: Namespace '': 
mkdir(/var/www/xxx/server-full/Maildir) failed: Permission denied 
(euid=1016(mozsync) egid=1016(unknown) missing +w perm: 
/var/www/xxx/server-full, dir owned by 0:0 mode=0755)
Apr 30 19:44:59 tornado dovecot: doveadm(mozsync): Error: sync: User 
init failed
Apr 30 19:44:59 tornado dovecot: doveadm(mozsync): Warning: I/O leak: 
0x414190 (line 102, fd 16)
Apr 30 19:44:59 tornado dovecot: dsync-local(cisco): Error: remote: 
doveadm(cisco): Fatal: User doesn't exist
Apr 30 19:44:59 tornado dovecot: dsync-local(cisco): Error: read() from 
worker server failed: EOF


Users mozsync and cisco are not valid mail users and it's not 
appropriate that Dovecot tries to create a Maildir for either of them. 
The users are system unprivileged users only, and do not ever send or 
receive mail.


And - I/O leak? ;)

Also, user cisco is local to one box only, and does not exist (nor does 
it need to) on the remote host.  So any complaints about this user are 
invalid and dovecot needs to ignore replication for this user anyway.



Fourth question, upon starting dovecot again, mail.log then spews 
several hundred of these messages:


Apr 30 19:45:06 tornado dovecot: dsync-local(reuben): Error: msg-get 
failed: box=Trash uid=114863 
guid=1335382569.M98089P29952.tornado,S=6479,W=6625


Before aborting entirely with:

Apr 30 19:45:09 tornado dovecot: imap: Server shutting down. in=328 out=2042

It seems to me that a a few of those problems logged could be solved by 
being able to specify which system users to synchronise, rather than 
Dovecot making a blind assumption that all users actually have valid 
Maildirs that need to be created, and all need to be sync'd between two 
hosts.


Subsequent delivery based sync'ing fails silently (pending more 
investigation) but I'd like to try and 

Re: [Dovecot] Dovecot dsync mail replication issues

2012-04-30 Thread Michescu Andrei
Hello Reuben,

I'm having a very similar setup. The 2 main differences: all my users are
virtual and the 2nd server is on a different continent (high latency
sync).

Unfortunately the dsync is not working for the moment. Timo is in the
process of redesigning it. So once it is release will know about it.


 drwx--  5 lyn lyn  4096 Apr 30 19:32
 .INBOX_7a86a62d465a974fb92f3b258734

 First question:  why is this random named directory being created in the
 origin Maildir?  Shouldn't the replication be more or less read-only in
 the origin Maildir?

- the number it is not random, but rather it is the GUID of the folder on
the other server. To get rid of this annoying problem you need to clean
your source of all these newly created folders, rsync your folders in
between the 2 machines, run dsync again (this time it will not mess up
with your folder structure)


 Second question:  If I re-attempt a doveadm sync a second time I get
 this error:

 tornado Maildir # doveadm sync -u lyn remote:r...@dustbowl.reub.net
 dsync-local(lyn): Error: Can't rename mailbox
 INBOX_7a86a62d465a974fb92f3b258734 to INBOX: Target mailbox already
 exists
 dsync-local(lyn): Error: Can't rename mailbox INBOX to
 INBOX_eb15f30ea563be4b70322bd68bb1: Renaming INBOX isn't supported.
 tornado Maildir #

 It's not clear if the second attempt has failed or succeeded, and it's a
 bit odd that it errors out on a directory that the dovecot sync process
 itself has created.


do the fix at Q1 and you will not run into this... it is not a permission
problem but rather a meta-info problem.

The setup will run fine as long as you only update 1 server and the other
one is backup. The current release does not handle well the master-master
model (you'll endup with emails like the folders above: duplicated, with
GUID appended to them etc etc)...

Wish Timo good luck and inspiration!

Best regards,
Andrei



Re: [Dovecot] Dovecot dsync mail replication issues

2012-04-30 Thread Timo Sirainen
On Mon, 2012-04-30 at 12:25 -0400, Michescu Andrei wrote:
  tornado Maildir # doveadm sync -u lyn remote:r...@dustbowl.reub.net
  dsync-local(lyn): Error: Can't rename mailbox
  INBOX_7a86a62d465a974fb92f3b258734 to INBOX: Target mailbox already
  exists
 The setup will run fine as long as you only update 1 server and the other
 one is backup. The current release does not handle well the master-master
 model (you'll endup with emails like the folders above: duplicated, with
 GUID appended to them etc etc)...

It does work, as long as you get the initial configuration to work
properly without adding the _GUIDs. The _GUIDs shouldn't be added if you
do the initial replication to the other side (to nonexistent Maildir!)
via dsync. I guess some plugins might also break this.

 Unfortunately the dsync is not working for the moment. Timo is in the
 process of redesigning it. So once it is release will know about it.

But yeah, the redesign is supposed to make all of this a lot easier and
more reliable. :) The new code can almost do the basics now, but still
needs some time.. I'm giving a talk about it in 3 weeks though, so I'm
planning on it being at least somewhat usable by then. :)