cPanel to cPanel Email Migration: Scripts and Steps

cPanel to cPanel Email Migration
This article will help you to migrate your cPanel emails to another cPanel account.

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 –

New Server – B

New Server IP –

Account Name – bil

Login to A server and run the below commands in the screen session.

rsync -arv /home/bil/mail/ root@
rsync -arv /home/bil/etc root@

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@$i/mail/; rsync -arv /home/$i/etc/ root@$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.

Share this post

Services to Explore

Stay up to date!

Stay up to date with the Web Hosting, Cloud and Server Management Industry News and Tutorials!

We will send you only the relevant emails, and we respect your privacy. Please review our privacy policy for more info.

cPanel & WHM Management Services

Focus on your business, and let us take care of your cPanel Servers!
From what you are reading, it seems you are interested in cPanel/WHM and related technologies. If you have a moment to spare, please take a look at our cPanel Management Services plan, and which might interest you even more!
cPanel Management Plan

Value-Added Services

We have services that can help you run a successful business. With us, you don't have to worry about these areas because our experts will take care of it for you.

ServerHealers uses cookies.