0

I have a client who created about 20 mailboxes on a server, and they have been using them for a few weeks. So there is mail in them, that can't be lost.

Now they recovered a backup of those mailboxes from an old hosting company, and they want me to merge those backups with the current mailboxes. I tried a lot of things with dsync and doveadm sync but I can't find the correct syntax, could someone help me ?

Basically, I just want to merge let's say /home/backup/account1/Maildir to /home/vmail/domain.tld/account1/. On this server account1@domain.tld will already be referencing /home/vmail/domain.tld/account1 according to the dovecot configuration, so I should be able to use -u if I understand it correctly, but how do I reference the backup ? looks like doveadm sync is only compatible with an other dovecot server, which I don't have ? I was thinking about just setting up a whole other mail server and using imapsync, which is really easy to use, but I think there must be a way to do it with doveadm sync or dsync that doesn't involve that must lost time. Thanks

0

I migrated some time ago mails from an hosting plan to my mail server merging mailboxes. As you I had a backup of maildirs that contains, in facts, a directory/files structure of your IMAP mailbox. If you do a ls -la into /home/backup/account1/Maildir you should see something like:

# ls -la
drwx------. 19 vmail vmail  4096  4 mag 18.15 .
drwxr-xr-x.  3 vmail vmail  4096 29 nov 17.23 ..
drwx------.  2 vmail vmail  4096  4 mag 18.15 cur
-rw-------.  1 vmail vmail   496  4 mag 18.15 dovecot.index
-rw-------.  1 vmail vmail 28656  4 mag 18.09 dovecot.index.cache
-rw-------.  1 vmail vmail    40  4 mag 18.15 dovecot.index.log
-rw-------.  1 vmail vmail 32864  4 mag 18.15 dovecot.index.log.2
-rw-------.  1 vmail vmail    23 15 feb 11.22 dovecot-keywords
-rw-------.  1 vmail vmail   360 29 nov 17.39 dovecot.mailbox.log
-rw-------.  1 vmail vmail   485  4 mag 18.09 dovecot-uidlist
-rw-------.  1 vmail vmail     8 29 nov 17.49 dovecot-uidvalidity
-r--r--r--.  1 vmail vmail     0 29 nov 17.37 dovecot-uidvalidity.565b29d3
drwx------.  5 vmail vmail  4096 15 feb 16.24 .Drafts
drwx------.  5 vmail vmail  4096 30 nov 10.38 .Job
drwx------.  5 vmail vmail  4096  3 mag 22.48 .Junk
-rw-------.  1 vmail vmail  3056  4 mag 18.09 maildirsize
drwx------.  2 vmail vmail  4096  4 mag 18.15 new
drwx------.  5 vmail vmail  4096 29 nov 17.39 .Newsletter
drwx------.  5 vmail vmail  4096 30 nov 10.38 .Personali
drwx------.  5 vmail vmail  4096 15 feb 16.24 .Sent
-rw-------.  1 vmail vmail   140 29 nov 17.39 subscriptions
drwx------.  2 vmail vmail  4096  4 mag 18.09 tmp
drwx------.  5 vmail vmail  4096 29 mar 22.44 .Trash

every .Something directory is an IMAP folder that contains:

# ls -la .Trash/
drwx------.  5 vmail vmail 4096 29 mar 22.44 .
drwx------. 19 vmail vmail 4096  4 mag 18.15 ..
drwx------.  2 vmail vmail 4096 29 mar 22.43 cur
-rw-------.  1 vmail vmail 7060 29 mar 22.44 dovecot.index.cache
-rw-------.  1 vmail vmail 3136 29 mar 22.44 dovecot.index.log
-rw-------.  1 vmail vmail   10  2 gen 20.46 dovecot-keywords
-rw-------.  1 vmail vmail  957 29 mar 22.43 dovecot-uidlist
drwx------.  2 vmail vmail 4096 15 lug  2015 new
drwx------.  2 vmail vmail 4096 29 mar 22.43 tmp

cur and new folders contains your mails for this IMAP folder (each file is a mail), tmp is a temp dir and should be empty:

# ls -ls .Trash/cur/
 4 -rw-------. 1 vmail vmail  2039 22 ott  2015 1445534803.M462117P23470V0000000000000901I000000000122C00E_0.srv-nya,S=2039:2,S
 4 -rw-------. 1 vmail vmail  1191  2 gen 20.45 1451763951.M751917P11002.srv-nya,S=1191,W=1223:2,Sa
64 -rw-------. 1 vmail vmail 64457  4 feb 14.57 1454594258.M272724P14796.srv-nya,S=64457,W=65380:2,S
 8 -rw-------. 1 vmail vmail  5163  7 feb 13.41 1454848911.M448032P9360.srv-nya,S=5163,W=5256:2,S
 4 -rw-------. 1 vmail vmail  2156 24 feb 10.18 1456305519.M460217P17448.srv-nya,S=2156,W=2200:2,S
 4 -rw-------. 1 vmail vmail  2193 24 feb 12.07 1456312052.M200955P5273.srv-nya,S=2193,W=2237:2,Sa
 4 -rw-------. 1 vmail vmail  2200 24 feb 12.12 1456312374.M662245P6161.srv-nya,S=2200,W=2243:2,Sa
 4 -rw-------. 1 vmail vmail  1518 21 mar 21.36 1458592592.M566137P20473.srv-nya,S=1518,W=1557:2,Sa
12 -rw-------. 1 vmail vmail  9784 29 mar 12.29 1459247350.M595698P12652.srv-nya,S=9784,W=9937:2,Sa
 8 -rw-------. 1 vmail vmail  5176 29 mar 13.10 1459249819.M474900P19505.srv-nya,S=5176,W=5269:2,Sa
 8 -rw-------. 1 vmail vmail  5325 29 mar 14.43 1459255390.M406958P2566.srv-nya,S=5325,W=5427:2,Sa
 8 -rw-------. 1 vmail vmail  5668 29 mar 19.08 1459271296.M76075P16861.srv-nya,S=5668,W=5765:2,Sa
 8 -rw-------. 1 vmail vmail  5673 29 mar 19.16 1459271792.M922218P18404.srv-nya,S=5673,W=5770:2,Sa
 8 -rw-------. 1 vmail vmail  5755 29 mar 20.12 1459275164.M71573P28250.srv-nya,S=5755,W=5853:2,Sa
 8 -rw-------. 1 vmail vmail  5622 29 mar 21.26 1459279615.M929486P8464.srv-nya,S=5622,W=5718:2,Sa

You also can see some dovecot.something files that are support files for dovecot and the maildirsize file that contains info about your IMAP quota (if enabled).

If your old hosting use something different from dovecot (like courier) you will see similar files with names like courier.*.

If you want to merge old and new mailboxes you can move all mails files (like 1459279615.M929486P8464.srv-nya,S=5622,W=5718:2,Sa) to corresponding directory in the new mailbox.

In order to do it you can:

  • TAKE A BACKUP COPY OF OLD AND NEW MAILBOX BEFORE START

  • Recursively remove all dovecot.* files and maildirsize from backup

  • Move/copy all other file to the new mailbox merging the directories (you should be able to do it with cd /home/backup/account1/Maildir && rsync -av --progress . /home/vmail/domain.tld/account1/). Note: file names of mails contains mailserver hostname usually, so you should not have filename conflicts.

  • Recursively fix permission/file ownership/SELinux context of new mailbox if needed

  • Remove the maildirsize file from the new mailbox in order to fix the quota count (dovecot will re-create it when a new mail is delivered to this mailbox fixing things)

  • From your mail client subscribe all IMAP folders (if needed and not done automatically)

This worked for me, if you want to try I recommend you to test it on a copy of a mailbox first (like create a new mailbox called test@yourdomain.com, copy in it all files of account1@yourdomain.com mailbox, fix permission/file ownership, check that it work trough webmail/IMAP client, merge mailboxes like said before, send a mail to test@yourdomain.com to force maildirsize creation and check again trough IMAP client that all mail all readable)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.