Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Plesk to cPanel E-mail migration  (Read 3174 times)

0 Members and 1 Guest are viewing this topic.

vinodt

  • Guest
Plesk to cPanel E-mail migration
« on: January 10, 2014, 10:15:02 am »
Login to Plesk Server

0.Suppose there are hundreds of accounts, so manually changing password is not an option. Simply run the script given below and that will change all mail account passwords to “Qwe123Qwe”

for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select concat(mail.mail_name,\"@\",domains.name) as address from mail,domains,accounts where mail.dom_id=domains.id and mail.account_id=accounts.id order by address"`; do /usr/local/psa/bin/mail -u $i -passwd_type encrypted -passwd 'Qwe123Qwe'; done


That will change all email password to “Qwe123Qwe”
==================

1.The script given below will give you the list of all email accounts in your server + the password.

Plesk:~# mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e "SELECT CONCAT_WS('@',mail.mail_name,domains.name),accounts.password FROM domains,mail,accounts WHERE domains.id=mail.dom_id AND accounts.id=mail.account_id ORDER BY domains.name ASC,mail.mail_name ASC;"
 +--------------------------------------------+-----------+
 | CONCAT_WS('@',mail.mail_name,domains.name) | password  |
 +--------------------------------------------+-----------+
 | new@example.com | Qwe123Qwe                            |
 | test@example2.com | Qwe123Qwe     
===================

2.Login to cPanel Server

In this cPanel server we have to create all emails that we have in the Plesk server. As I mentioned before, If it just one or two email we can manually do it. But suppose we have lot of email accounts. So we have to write a script for that and I already did. First create a file called “/home/mail.accounts”  with the name of all email account that you have to create ( which you already have ).

( Note : I assume you already created all domain account in the server )

root@cPanel [~]# cat /home/mail.accounts
 new@example.com
 test@example2.com

===================

Now, run the script given below and that will create emails account given in “/home/mail.accounts” with the password “Qwe123Qwe”

for i in $(cat /home/mail.accounts); do /scripts/addpop $i 'Qwe123Qwe'; done

So now we created the same email account in our cPanel server now it’s time to sync the mail contents with IMAPCopy.

3.Let’s install IMAPCopy

root@cPanel [~]# cd /opt/

root@cPanel [/opt]# wget http://home.arcor.de/armin.diehl/imapcopy/imapcopy.tar.gz

root@cPanel [/opt]# tar -xvf imapcopy.tar.gz

imapcopy/
imapcopy/imapcopy
imapcopy/ImapCopy.cfg

root@cPanel [/opt]# cd imapcopy
root@cPanel [/opt/imapcopy]# ls
./ ../ imapcopy* ImapCopy.cfg


As you can see, it’s a simple tool. Just have two files. “imapcopy” is the shell executable and “ImapCopy.cfg” is the configuration file.

4.Open the “ImapCopy.cfg” and you can see the sections below.

#############
 # Sourceserver
 ##############
 SourceServer localhost
 SourcePort 143

###################
 # Destinationserver
 ###################
 DestServer localhost
 DestPort 143

#############################
 # List of users and passwords
 #############################
 # SourceUser SourcePassword DestinationUser DestinationPassword
 Copy "foo" "foosrcpw" "foo" "foodestpw"
 Copy "bar" "barsrcpw" "bar" "test"

5.You already know what to do. Under the “Sourceserver” section, give the source server IP/Hostname and IMAP port. In this case you don’t have to change anything because the source server is this machine. Then under the “Destinationserver” section, give the Plesk server IP/Hostname and IMAP post. ( You can run this same script from Plesk server. Just need to change the source and destination server configurations )

6.Then you can see the section “List of users and passwords”. Here you have to specify the EMAIL user account and password details ( Both source and destination ). We already have the list of email accounts and passwords that you have in the Plesk server. ( I told you to save the emails in a separate file. Remember? If you forgot, just drag the page up and you can see the for loop script )

7.Before adding the EMAIL details you have to comment the test accounts under “List of users and passwords” section.

sed -i 's/^Copy/#Copy/g' /opt/imapcopy/ImapCopy.cfg

8.Now you can add the email details. If you have just number of emails, just add it manually or please run the script given below.

( Note : We have the email account names in – “/home/mail.accounts” file. If your file name is different, make sure to change that in script. Also, I have set all email account passwords ( Both in source and destination server ) to “Qwe123Qwe”. If you set it something else, make sure to change that also. )

for i in $(cat /home/mail.accounts); do echo "Copy \"$i\" \"Qwe123Qwe\" \"$i\" \"Qwe123Qwe\"" >> /opt/imapcopy/ImapCopy.cfg; done

9.Now you are all set. Before starting the migration if you want to test the working, you can run imapcopy script with “-t” switch.

root@cPanel [/opt/imapcopy]# ./imapcopy -t

10.If you find any connection issues, correct it and then you can start the migration just by running the imapcopy script.

( Note: If there are lot of mails or if you are having account with huge size, then make sure to run this in screen session. )

root@cPanel [/opt/imapcopy]# ./imapcopy

11.That’s it! You can see it migrating each and every account just like that. After the migration, you can verify and I’m sure there will be a smile on your face because you just completed a Plesk to cPanel email migration. :)

Regards,

Vinod T K