Copy all email accounts from one CPANEL server to a second, possible?

rappel

Registered
Mar 22, 2023
1
0
1
UK
cPanel Access Level
Website Owner
I've seen a few similar questions but only in regard to email content and how to do it. So apologies if I have missed something that explains what I am asking here.

I find that I need to transfer about 40 email accounts, from one cPanel based account to another cPanel based account. They are on subdomains (if that makes a difference) with the DNS entries pointed at the hosting co. servers. The hosting provider says they don't do this at all, so I suspect that this has a few gotcha's in the way of anything but manual methods.

I have what I believe to be full access to cPanel, but not WHM. There may of course be things missing tho' I'm not an expert in this highly configurable environment.

What I would like to be able to do is:

  • Back up all emails hosted in old account. Ideally in one go.
  • Copy the complete environment over to the new account. Including all the email account details, passwords etc.
    i.e. I don't want to have to manually recreate all the accounts on the new environment as I don't have the passwords for some of the email accounts and I want this to be as painless as possible for the users, some of whom are in their ninth decade and need patient support when things go wrong (well I'd like it to be painless for me too!)
  • Change DNS to point the mail at the new servers.
  • Check for completion of DNS move. I can in theory make this quite short by reducing TTL on the MX records for a period I think but it will still need a final -
  • Sync the last period's worth of emails that have arrived on the old server to the new account's email accounts.

If I'm reading it all correctly there's little in cPanel itself to assist with this in terms of automation?
I'm happy to do this manually with file transfers if that will work, but what I don't know at this point is:

Are all cPanel instances equal i.e. do they all use Maildir++ format for mail storage? If not, how do I find out as a Cpanel admin what is used?
If they all use MailDir++, is it safe to copy files and directories over manually?
Does the file structure around the MailDir directories in a cPanel environment explicitly or implicitly contain the account names and passwords?
(To be honest, this is going to be the major PITA - recreating all the accounts one by one)

The final sync may be problematic if there's no tool. So if that's not going to happen, is there mileage in temporarily pointing the DNS to a non-existant server, waiting for that to complete so that I can copy files across in the background knowing the source email accounts won't be updated, then point the DNS back to the new server and just allow the normal delay/retry of the MTAs to buffer mail in transit?


Any help and advice gratefully received.
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
16,570
2,612
363
cPanel Access Level
Root Administrator
Hey there! As you've found, there's not a good way to do this as we don't have a tool available for this type of work. You could always submit a feature request using the link in my signature, and then I can bring that up with the team.

To clarify a few points:

Are all cPanel instances equal i.e. do they all use Maildir++ format for mail storage? If not, how do I find out as a Cpanel admin what is used?
No, cPanel servers can use either maildir or mdbox. You'll be able to tell the difference in the file structure of the mail directory - if you see things like /cur and /new, that's maildir, if you see INBOX, Archive, Sent, that's mdbox.

If they all use MailDir++, is it safe to copy files and directories over manually?
Yes, these are just flat files on the system.

Does the file structure around the MailDir directories in a cPanel environment explicitly or implicitly contain the account names and passwords?
(To be honest, this is going to be the major PITA - recreating all the accounts one by one)
No - this is stored in /home/username/etc/domain.com in various password, quota, and shadow files. Manually integrating that into an existing cPanel account could certainly be doable, but it would be difficult as you'll have to manually copy each line of the file you need.

I wouldn't use any tools that involve having to change the DNS. You could use a third-party tool like Imapsync to move messages, or you could use rsync between the two machines if your cPanel user has SSH access.

The short story - there isn't an easy way to do this, and I don't have any step-by-step instructions on my end since it's not something we support.
 

DennisMidjord

Well-Known Member
Sep 27, 2016
361
80
78
Denmark
cPanel Access Level
Root Administrator
We've done this many times, although not in the scale you're trying to do. It's always been email accounts for a few domains or so. All of our accounts are configured as Maildir.

What we usually do is copy both the /home/username/etc/domain.com/ and /home/username/mail/domain.com/ directories to the new server. Once that's done, we set the permissions (`chmod -R username:username /home/username/etc/domain.com/ /home/username/mail/domain.com/`) and then run `/scripts/mailperm username`. That would be everything required for migrating to email accounts to a new server.

The above is pretty easy and shouldn't take long.
For syncing emails that are received by the old server while DNS changes are propagating, you could write a small shell script that runs every 5-10 minutes and looks for new files. Once a new file is detected, send it to the new server and update the permissions again. If you know the passwords for the accounts, it would be far easier to use a tool such as IMAPSync.