Since there is no inbuilt option in cPanel to migrate only emails, ever wonder how to perform a cPanel to cPanel email migration?
Suppose we performed a cPanel to cPanel migration, but the customer took a long time to switch the DNS. So in between this DNS switch, all data and emails will go to the old server, and we will be lost it. In this situation, we may have to perform an email migration again. You can find the steps below.
In cPanel, the emails are stored under the “/home/account_name/mail/” directory, and the email password and account details are stored under the “/home/account_name/etc” directory. So what we are going to do is to rsysnc these two directories.
Old Server – A
Old Server IP – 192.168.1.1
New Server – B
New Server IP – 192.168.1.2
Account Name – bil
Login to A server and run the below commands in the screen session.
rsync -arv /home/bil/mail/ root@192.168.1.2:/home/bil/mail/ rsync -arv /home/bil/etc root@192.168.1.2:/home/bil/etc
You can follow these steps when you want to migrate the emails for only one account. But what if there are a huge number of accounts and rsyncing every single account one by one won’t be practical. So we can use a for loop script in this case.
Please note that, before proceeding with this script, we have to enable automatic rsync login ( login without password prompt ). You can find the steps in the article- SCP SSH and Rsync without prompting for password
As you know rsync uses ssh protocol to transfer data. So what we have to do is
for i in 'cat /etc/trueuserdomains | awk {'print $2'}'; do rsync -arv /home/$i/mail/ root@192.168.1.2:/home/$i/mail/; rsync -arv /home/$i/etc/ root@192.168.1.2:/home/$i/etc/; done
That will migrate all your cPanel emails accounts and user accounts to the new server.
Give it a try, and do let me know if you need any further help.