Tuesday, January 4, 2011

email server migration - Sendmail - Postfix - LDAP

I am given with a task to migrate emails from a sendmail server to postfix server. The was a complex task, because of following reason.
- There were many virtual domains
- The sendmail was using mailbox and postfix was using maildir
- The sendmail authentications was on passd files and the postfix's user profile was on LDAP
- The users who are migrated to postfix will get a emails with new domain which was there in postfix and users should be able to use both emails using single account.

I learnt a lot by doing this. I will share that here.

Migrating virtual domain accounts
Sendmail had several virtual domains
eg. xxx.ttt.lk, nnn.mmm.lk etc. All these were created under /etc/vmail/alias.xxx.yyy.lk, alias.nnn.mmm.lk etc. In /etc/vmail the respecting passwd and shadow files also were there.

There I extracted all the users information and made a ldif file so that I can create users on LDAP server. To do that I developed a PHP scipt which reads the information from an excel file and output a ldif file.

When I do this, I add all the mail accounts are mail alias in LDAP.

Another issue I found when I do this was, some password on the old sendmail system was in Unix crypt format. However in the new postfix server it was decided to use the md5crypt. Since the Unix crypt use fixed salting, I used a default md5crypted password for existing Unix Crypted password.

Using the generated ldif file, I created the accounts on LDAP server

Then another issue was how to have all the sendmail virtual domains in postfix. I found that in postfix configuration there is a pasrameter called virtual_domains where I listed all the virtual domains of sendmail so that the postfix will start allowing those domains.

In addition to that I had to do the change in the DNS server as well so that here after all the xxx.yyy.lk and nnn.mmm.lk will be sent to new postfix server.

Moving mailbox to maildir

Other issues was moving existing mailbox of users in sendmail to maildirs in postfix.
To do this, I used a tool called mb2md (http://batleth.sapienti-sat.org/projects/mb2md/)
This tool has several options.
However to use this tool, your system also should have date::parse perl

I installed this using following way :

perl -MCPAN -e 'SHELL'
Install Date::parse

After installing this I added executable access to downloaded mb2md perl script.

Thereafter I ran the script as follows :

./mb2md -s /var/spool/mail/user1 -d /opt/maildirs/user1

Then I also prepared the existing mailbox folders (which were located in /vhome/user1) as maildirs using following command :

./mb2md -s /vhome/user1 -R -d /opt/maildirs/user1

when I ran these command it was showing how many messages got extacted and how many folders have been created etc.

After creating these maildirs I moved them to the respecting locations in the postfix server and provided the owenership to vmail (in my case it was vmail. This user should be defined in main.cf file.

Hope this will help