Migrating email accounts from a cPanel hosting environment

Hey guys,

After a little bit of futzing around, I think I’ve figured out a good way to transfer email accounts in bulk from a cPanel shared hosting account to a mail-in-a-box server. See this Gist:

Please note that this is a work-in-progress, drawn from my own digging and experimenting. Let me know if you see anything that is incorrect, missing, or needing clarification. I take no responsibility for any lost data!

Not something I need, but good work. Sure it will come in useful for some people!

Looks great!

Just a quick question. In the .php files it has mentions of example.com/shadow. Should i change this or do i leave it as is?

You should change that to the path for you actual shadow file in your cpanel account.

I see. I assume I’ll have to change the domain for every domain I bring across?

Yup. If you have a lot of domains, I’d start by doing one just to make sure it is working as expected. After that, you could probably just modify the script so it loops through the rest of your domains.

Great. Thanks for the great work and code! One last noob question. How do you run the php code?

The stock answer is that MiaB is for hosting email. To keep things stable, host PHP somewhere else.

That said, there’s a forum post on here that talks about how to do it.

I think @jamiele23 is just asking how to run PHP from the CLI in general, not on the MiaB server specifically. My script is a one-time script that can be run on any machine - it doesn’t need to be run on the mail server.

As long as you have PHP installed on your machine, you can simply run it by doing

php convert_user_accounts.php

For more examples, see http://www.jarrodoberto.com/articles/2011/12/running-php-from-the-command-line-basics

Oops, you’re right. Sorry for not scrolling up!

Great thanks, however where should I be storing this file? In the root directory?

root@box:~# sqlite /home/user-data/mail/users.sqlite
Unable to open database “/home/user-data/mail/users.sqlite”: file is encrypted or is not a database

Anyone else having this issue?

i assume you are using sqlite, use sqlite3 “/home/user-data/mail/users.sqlite”

Good work!

Really like this idea. Personally, I’d prefer a script like imapsync, because it’s more versatile - but for some complete overkill and more difficult to setup due non standard dependencies.