Virtualmin comes with a script that will migrate accounts from a cPanel server, using cPanel backup files.
First, you create and download a backup file for the account, using the "Backup" function for the account in cPanel or WHM.
Then you go to your Virtualmin and access: "+Add Servers => Import Virtual Server" .
Unfortunately I found that this method did not always work for me. I encountered some errors when trying to use it, such as "Multiple Domains" or "Email Aliases". Maybe Virtualmin will be able to get this working better in future releases but for now I needed a way to manually transfer the accounts for each domain from cPanel to my new Virtualmin setup.
The first step was actually creating the new Virtual Server on Virtualmin. Pretty easy. The Menu Item on Virtualmin is: "Create Virtual Server". You can select a custom username that matches your existing cPanel setup. A new database will automatically be created for you. You can then go into "Edit Databases" and change the database name to match the database on your old cPanel installation. Also note the database user and password, by using the corresponding tabs These can also be updated to match your existing database user and password if desired. If you need additional databases they can also be created.
Transferring the website(s) and associated database(s) themselves to the new server is pretty straightforward. With root access on ssh, you can use rsync to simply copy the files from the public_html, and/or other relevant directories, to the new host, making sure the owner and group are correct for permissions, then dump file(s) from the database(s) using mysqldump, to be restored to the new database(s) on the Virtualmin server.
(In the following examples, "old" means on the cpanel server, and "new" means on the Virtualmin.server.)
TRANSFERRING THE FILES FROM cPanel:
The following example begins while logged in as root on the "old" server.
--of course, if being logged in as the root user is (understandably) not comfortable or possible for you, prepend "sudo" to each command below. You will need to change all the values indicated in bold type, to match your situation.
# rsync -avz /home/oldusername/public_html/ root@newservername:/home/newusername/public_html
# mkdir /home/oldusername/sqlbak
# mysqldump olddatabasename > /home/oldusername/sqlbak/newdatabasename.sql
# rsync -avz /home/oldusername/sqlbak/ root@newservername:/home/newusername/sqlbak
Alter these commands appropriately for any subdomains which may need to be transferred onto the "new" Virtualmin server (Virtualmin's file structure is a bit different from cPanel. For each subdomain it creates a separate directory containing a public_html directory within it, under a directory called "domains.")
SETTING UP THINGS FOR VIRTUALMIN:
Now logged in as root on the "new" server to complete the transfer.
I did hit one snag in the database transfer: the mariadb server threw me an error message when I tried to run:
# mysql -v -p newdatabasename < /home/sqlbak/newdatabasename.sql
Overcoming that error was pretty easy, the database dump files from cPanel had a line (the first line, right on top) which had something to do with "mysql sandbox." All I had to do was open the .sql file in a text editor (like nano) and remove line #1. --then I re-ran the above command and it worked fine.
Next, I made sure the ownership of all files in public_html was correct:
#chown -Rf newusername:newusername /home/newusername/public_html
Voila! If the domains, usernames, database names and database passwords are identical on the old and new servers respectively, everything should work right away: --otherwise there may be some further adjustments to be made.
TRANSFERRING EMAIL ACCOUNTS:
The next challenge was migrating the email accounts. Thanks to a tutorial I found online written by Ali Khallad, this also became a pretty simple process, containing just a few steps.
Again, cPanel uses a different file structure than does cPanel. CPanel puts everything regarding its email accounts in a single "main" directory called "/home/oldusername/mail". A subdirectory tree containing each domain and its subusers lies within this main directory. In Virtualmin the main email for the domain is in the /home/newusername/Maildir directory, owned by the main user. Separate Maildir directories are then created for each additional email in a directory tree under "homes." The owner usernames for these Maildir sub accounts are then modified to become the complete email address (with @domain). **
The first step was to transfer the email files themselves. This is similar to how I transferrred the website files, using rsync
First, on Virtualmin's GUI panel, go to Edit Users=>Add New User and create the new email subaccount newemailsubuser@domainname. Select email only, unless you want this user to have FTP access. This will result in a new directory having been created at /home/newusername/homes/newemailsubuser/Maildir
.
Logged in as root at the "new" server (the Virtualmin machine):
Then the rsync command looks something like this:
# rsync -avz root@oldservername:/home/oldusername/mail/domainname/oldemailsubuser/ /home/newusername/homes/newemailsubuser/Maildir
I found there were, in some cases, certain extraneous files that were unneccesary in the Virtualmin dovecot configuration so I removed those (optional):
# rm -Rf /home/newusername/homes/newemailsubuser/Maildir/dovecot*
# rm -Rf /home/newusername/homes/newemailsubuser/Maildir/courier*
Then make sure the ownership is correct:
# chown -Rf newemailsubuser@domain:newusername /home/newusername/homes/newemailsubuser/Maildir
Now ensure that all permissions are set 644 for files and 700 for directories:
# find /home/newusername/homes/newemailsubuser/Maildir -type f -exec chmod 644 {} /;
# find /home/newusername/homes/newemailsubuser/Maildir -type d -exec chmod 700 {} /;
Index and resync the files using the doveadm command:
# doveadm index -u newemailsubuser@domain '*'
# doveadm -D force-resync -u newemailsubuser@domain '*'
This should do the trick, but Ali suggests that creating and deleting a file in each directory might help, if some of the emails still don't display properly:
# find /home/newusername/homes/newemailuser/Maildir -type d -name cur -exec sh -c 'f="{}/.refresh"; touch "$f" && rm -f "$f"' \;
''**To transfer the "main" domain email account, use the same basic procedure, except you would transfer the main /home/oldusername/mail directory on cPanel to the /home/Maildir directory on Virtualmin. Then on the Virtualmin server you can go ahead into /home/Maildir and remove the domain-named subdirectories. For file ownership, use just the main newusername, without appending the @domain.
- Log in to post comments