Migrate postfix to another server with same domain

migrationpostfix

I need to migrate server with Postfix. IPs will be different, domains will be same (example.com) What problem:

I've moved all settings and mailboxes from old server(1.1.1.1) to new(2.2.2.2). On new server Postfix is working.

When I change MX record in named from old IP to New IP, some of user still would be sent mails to old server and some to new.

The solution that I came up with is sync Maildir/new folders.

More beautiful solutions, that I've found is using /etc/postfix/transport on old server (for one subdomain):

example.com smtp:[2.2.2.2]:25, but messages still comes to old server. If I remove use1@exmamle.com from /etc/postfix/virtual, I have error, that user user1@example.com no in aliase_table on server.

Can anybody help me?
Thanks.

Best Answer

Make your old server a mx backup of the new one. For this you will need to have both servers as MX for your domain, but the old must have a bigger number as priority:

   example.com.     IN MX 10 2.2.2.2
   example.com.     IN MX 20 1.1.1.1

Then you can add your domain into relay_domains:

   relay_domains = $mydestination, example.com

Important to note that your relay_recipient_maps must be empty, and the mydestination, virtual_alias_domains and virtual_mailbox_domains must not contain your domain, in this case example.com.

This will make your old server accept and queue the message to send to your new server after.