I have been assigned a task by the big boss to do our company’s email migration without any downtime. Downtime in this case is refer to the time when MX record pointing propagates around the world to the new server. It could cause your emails to be sent to the old server, instead of the new server until the client DNS server clear their DNS cache of the host record.
To achieve this, we need to have a server in between to be the store-and-forward mail server aka backup MX server. Point the MX record to this server and then we change the forwarding IP from old server to the new server. So every new email will be sent directly to the new server without any propagation delay. Following picture shows what will be happened when migrating email server:
I am using following variables:
Backup MX Server: 220.127.116.11
Backup MX OS: CentOS 6.2 64bit
Old mail server: 18.104.22.168
New mail server: 22.214.171.124
Backup MX server
1. To eliminate DNS propagation during migration, we will need to setup a backup MX server at least 3 days before the migration been scheduled. We will use Postfix, a mail transfer agent to serve as store-and-forward mail server. Install Postfix via yum, turn off sendmail and SELINUX:
$ setenforce 0 $ service sendmail stop $ chkconfig sendmail off $ yum install -y postfix
2. Edit /etc/postfix/main.cf using text editor as below:
myhostname = forwarder.mygreek.biz #server hostname mydomain = localhost myorigin = $mydomain inet_interfaces = all #listen to all available IPs mydestination = $myhostname, localhost.$mydomain, $mydomain mynetworks_style = host relay_domains = mygreek.biz transport_maps = hash:/etc/postfix/transport
3. Open /etc/postfix/transport to setup the forwarding for relayed domain. Point it to the old server:
4. Activate the Postfix map, start the Postfix service and enable the service on boot:
$ postmap /etc/postfix/transport $ chkconfig postfix on $ service postfix start
Backup MX should able to receive and forward emails to the old mail server now. Dont forget to allow port 25 via IPtables so Postfix can run smoothly.
MX record in NS
Once the backup MX server ready, we then need to update the MX records in the name server. Login into the name server and update the MX records and point it to this backup MX:
mygreek.biz. MX 10 mail.mygreek.biz. mail A 126.96.36.199
Make sure you are doing this at least 3 days before the migration start to avoid DNS propagation affect the migration.
1. Before we start the migration, we will need to stop old server mail service. Since the old server is using cPanel, I will need to stop and disable Exim service so backup MX can take over to store the email in queue until the new mail server up:
WHM > Service Configuration > Service Manager > Unchecked “Enabled” and “Monitor” for Exim > Save
2. I will use cPanel migration utility called “Copy an account from another server”. Just follow the wizard and wait until the account copy complete.
3. Once the email migration completed, we then need to update the forwarding IP in the backup MX to the new server. Login into the backup MX server and edit /etc/postfix/transport:
Then, update the Postfix mapping and restart the service to push the emails in queue to the new mail server:
$ postmap /etc/postfix/transport $ service postfix restart
In new server, you will notice that you will start to receive emails which already in queue from backup MX server. This will guarantee no lost email and eliminate email being sent to the old server.
Completing the Migration
Monitor the email flow for a while and make sure all emails are delivered to the recipient respectively. If everything run smoothly, it is time to update the MX record and point it to the new mail server so we can remove the MX backup server later:
mygreek.biz. MX 10 mail.mygreek.biz. mail A 188.8.131.52
Please allow the MX backup server to run at least 3 days to make sure new MX has propagated around the world. To double confirm on this, you can use this website to check whether your mail host has been propagated or not:
If everything run smoothly, you can shut down and remove the backup MX server and migration consider completed.