How-to: big cPanel email-only server migration

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
10,137
Location
LT, EU
We've received some requests to write a guide on how to migrate email-only server. First step would be to create a cPanel backup without email data, but with email accounts. Something like this might help:
https://forums.cpanel.net/threads/s...mail-accounts-and-without-public_html.264611/

You could then use the same "pkgacct" command for all the accounts, just like mentioned in https://forum.directadmin.com/showthread.php?t=58059.

When you get the account backup ready, please use https://forum.directadmin.com/showthread.php?t=58059&p=296439#post296439 to migrate it (DA might support direct cPanel backup restores in GUI soon, but CLI is the only option now).

With these steps done, please make sure you see the accounts in DirectAdmin. Then you may use rsync on your DA server to sync FROM cpanel. A script would look like this (just wrote, so, would need some testing), don't forget to change the IP:
Code:
#!/bin/sh
#Change IP to the real one, make sure we're able to login without password to it (SSH keys)
CPANEL_SERVER_IP=8.8.8.8

for u in `ls /usr/local/directadmin/data/users`; do
{
  echo "doing ${u}"
  for d in `grep ": ${u}$" /etc/virtual/domainowners | cut -d: -f1`; do
  {
    echo "domain: ${d}";

    for e in `cat /etc/virtual/${d}/passwd | cut -d':' -f1`; do {
        if [ ! -d /home/${u}/imap/${d}/${e}/Maildir ]; then
            mkdir -p /home/${u}/imap/${d}/${e}/Maildir
        fi
        rsync --delete -at root@${CPANEL_SERVER_IP}:/home/${u}/mail/${d}/${e}/ /home/${u}/imap/${d}/${e}/Maildir/
        /usr/local/directadmin/scripts/set_permissions.sh maildir ${u} /home/${u}/imap/${d}/${e}/Maildir
        echo "${e}@${d} has been synchronized!"
    };
    done;
  };
  done;

  echo "";
};
done;

For single account (to test), you can just run the following instead of the script for all the account (replace uppercase strings with real ones):
Code:
rsync --delete -at root@YOUR_SERVER_IP:/home/USER/mail/DOMAIN/EMAIL/ /home/USER/imap/DOMAIN/EMAIL/Maildir/

Example, to sync [email protected], if account name is myuser and server IP is 8.8.8.8:
Code:
rsync --delete -at [email protected]:/home/myuser/mail/yourdomain.com/info/ /home/myuser/imap/yourdomain.com/info/Maildir/

Troubleshooting:
-----
If you notice any issues, these might be permissions related, to fix them:
Code:
/usr/local/directadmin/scripts/set_permissions.sh maildir myuser /home/myuser/imap/yourdomain.com/info/Maildir

If something is still not okay (shouldn't be), you can simply remove dovecot index files:
rm -f /home/myuser/imap/yourdomain.com/info/Maildir/dovecot*
-----

Steps:
1) Backup cPanel account without email data
2) Restore it in DirectAdmin
3) Run rsync command, wait for it to finish
4) Can do internal testing now to see if everything is here
5) You can now re-run rsync command, it'd just transfer the differences if there are any, and you're done :)

Thank you!
 
Last edited:
  • Like
Reactions: Kal
Hi smtalk,

Great script!!! I was looking for how to move only emails accounts.

This is also valid if I have already created manually the emails accounts, isn't it?

I only jump to step three and run the script, correct?

Thank you!!!
 
Hi smtalk,

Great script!!! I was looking for how to move only emails accounts.

This is also valid if I have already created manually the emails accounts, isn't it?

I only jump to step three and run the script, correct?

Thank you!!!

Yes, if you just need to sync the data :)
 
if i want to do it manually can i just transfer all the files from the info folder in cPanel to Maildir folder in DA?
 
Followed by a cPanel-to-DA server migration, customers are facing IMAP sync issues. I have used GUI to do migrate as described in (https://forum.directadmin.com/threads/how-to-cpanel-to-da-migration.58059/#post-296438)

The issue for IMAP is that their folders on mail clients (Outlook etc.) are no longer syncing unless they recreate the IMAP account on their email client (few customers got it fixed by this way).

Also, few clients reported creation of numerous Drafts, Archive, Sent Items folder creations on their Outlook/webmail as well. This too sorts when the user recreate their IMAP account.

What could be the reason for this behavior. Is this anything to do with dovecot index files as stated above by "smtalk":

"If something is still not okay (shouldn't be), you can simply remove dovecot index files:
rm -f /home/myuser/imap/yourdomain.com/info/Maildir/dovecot* "

Thanks.
 
Do you get any IMAP connection errors there? Maybe they have old server listed (the one you migrated from) as IMAP server?
 
Thanks for your quick response, Will be checking logs further and update here.
 
Step 1: Create a new email account on the NEW SERVER with the same address and password. You can do this by going into the cPanel on the NEW SERVER and click on Email Accounts.
Step 2: Download the files off of the OLD SERVER. ...
Step 3: Transfer files to NEW SERVER. ...
Step 4: Reset Mail Quota. ...
Step 5: Change DNS. ...
Step 6: Test

Admin,
O365CloudExperts
 
For single account (to test), you can just run the following instead of the script for all the account (replace uppercase strings with real ones):
Code:
rscync --delete -at root@YOUR_SERVER_IP:/home/USER/mail/DOMAIN/EMAIL/ /home/USER/imap/DOMAIN/EMAIL/Maildir/

Example, to sync [email protected], if account name is myuser and server IP is 8.8.8.8:
Code:
rscync --delete -at [email protected]:/home/myuser/mail/yourdomain.com/info/ /home/myuser/imap/yourdomain.com/info/Maildir/

Thanks, very useful! Just a bit of a code typo there with 'rscync'.
 
Back
Top