Upgrading / Migrating to a New cPanel Server

ruzbehraja

Well-Known Member
May 19, 2011
392
11
68
cPanel Access Level
Root Administrator
Scenario:
Server hardware is old. We want to shift to a new server keeping the IP's the same.
Both machines have WHM / Cpanel latest version. Both have identical configurations and config files updated for both.

Issue:
After the Accounts are all pulled to the new server through WHM, the Datacenter has to be informed about the IP Switch from old to new server.

This may take from 15 minutes upto a few hours for them to respond to the support ticket and actually do the switch. Or we could also schedule this for a fixed date / time in future.

The Question:
I wanted to know if there is an effective way of keeping the servers "synced" uptil the last few minutes before the switch.

Mainly to ensure that MySQL, Email and Website data is updated and latest on the new server.

- - - Updated - - -

I read an interesting article at http://bobcares.com/blog/?p=97 which has exactly what I want.

However, I was wondering whether rsyncing had any drawbacks.

I was especially concerned about whether rsyncing, and repairing the databases was foolproof.

I ask this, since I have seen a lot of threads with cpanel techs being apprehensive about using rsync.

Rsync
Once the account moves are done, the next thing would be that till the ip changes, nameserver changes are done for the accesses to be directed to the accounts on the new server, we would need to ensure that they are synchronized and no data is lost.
To rsync, follow these steps:
a) Setup ssh-key
b) rsync the folders /home , /var/cpanel , /var/lib/mysql , /usr/local/cpanel/3rdparty/mailman , /usr/local/cpanel/base/frontend , /etc/valiases , /etc/vdomainaliases , /etc/vfilters using the commands
for user in `cat /home/tomove`;
do rsync -avuz -e ssh [email protected]:/home/$user/ /home/$user; done

rsync -avuz -e ssh [email protected]:/var/cpanel /var/cpanel

rsync -avuz -e ssh [email protected]:/var/lib/mysql /var/lib/mysql

rsync -avuz -e ssh [email protected]:/usr/local/cpanel/3rdparty/mailman /usr/local/cpanel/3rdparty/mailman

rsync -avuz -e ssh [email protected]:/usr/local/cpanel/base/frontend /usr/local/cpanel/base/frontend

rsync -avuz -e ssh [email protected]:/etc/valiases /etc/valiases

rsync -avuz -e ssh [email protected]:/etc/vdomainaliases /etc/vdomainaliases

rsync -avuz -e ssh [email protected]:/etc/vfilters /etc/vfilters
Fixing Databases
Once rsync is completed, you need to repair the mysql databases since they get corrupted.
By running /scripts/fixmysql on the new server and verifying if the databases are showing to be ok, you can ensure that there is no corruption in databases. Just run the following commands after going to /var/lib/mysql on the new server

/scripts/fixmysql;/usr/bin/mysql_fix_privilege_tables;/usr/bin/mysqlcheck -A --auto-repair;myisamchk -r -e ./*
Setting up Cron
You can setup Cron scheduler to repeat the rsync every couple of hours till the IP’s on the old server are changed to that of new servers. This ensures minimum loss of data.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,229
463
Hello :)

My advice is to avoid using rsync to synchronize data unless absolutely necessary. Instead, you should consider using the following option when transferring the accounts to the destination server:

Express Transfer

This will route traffic over to the destination server as soon as the account is transferred, provided the DNS for the domain names is handled on the source server.

Thank you.
 

ruzbehraja

Well-Known Member
May 19, 2011
392
11
68
cPanel Access Level
Root Administrator
Thanks for the info regarding rsync.

I don't think the Express Transfer is for my scenario (or maybe I didnt understand it properly).

But I wouldnt want any changes in the DNS, because I will be switching the IP and retaining the old IP anyway.

So what Express Transfer would do is give all the domains a new IP and then after the old IP is switched to the new server, I would need to change all the A records back to the Old IP.

Any other solution to keep the data synced would be appreciated.

Thanks.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,229
463
So what Express Transfer would do is give all the domains a new IP and then after the old IP is switched to the new server, I would need to change all the A records back to the Old IP..
This is the recommended solution because you can easily convert the accounts back to the original IP address when necessary via:

"WHM >> IP Functions >> IP Migration Wizard"

The IP Migration Wizard is documented at:

IP Migration Wizard

However, feel free to use another method if you find one that better suites your specific requirments.

Thank you.
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
You should only be worried about using rsync if you are rsycing without doing initial cPanel account transfers or doing it and copying over some files and folders that should never be copied (such as /var/cpanel/sysinfo.config file).

Using rsync is detailed here but it's in the scenario where the old machine isn't able to do a regular cPanel transfer:

http://forums.cpanel.net/f5/rsync-backups-160054.html#post671150

So my suggestion is just to do WHM > Transfer area to copy all the accounts over first, then to rsync the data using the above as a guide.

Since the new server won't be live yet, you should be able to confirm if everything is working properly before you push it live. You'll still have the old one able to be used if the new one fails, so I'm never certain why people claim rsync is a bad idea for someone who does know what they are doing in Linux. Anything you do can be a terrible idea in command line if you don't know Linux.

Of note, if you use rsync and the new server ends up having issues, we won't support the issues created by rsyncing it. Please keep that in mind.
 

ruzbehraja

Well-Known Member
May 19, 2011
392
11
68
cPanel Access Level
Root Administrator
This will route traffic over to the destination server as soon as the account is transferred, provided the DNS for the domain names is handled on the source server.

Thank you.

In my case, the DNS for the domains is not handled by the CPanel Server, it is handled at the domain registrar end.

Thanks for your suggestions Tristan.

Still looking out for some other solution.

- - - Updated - - -

You should only be worried about using rsync if you are rsycing without doing initial cPanel account transfers or doing it and copying over some files and folders that should never be copied (such as /var/cpanel/sysinfo.config file).

Using rsync is detailed here but it's in the scenario where the old machine isn't able to do a regular cPanel transfer:

http://forums.cpanel.net/f5/rsync-backups-160054.html#post671150

So my suggestion is just to do WHM > Transfer area to copy all the accounts over first, then to rsync the data using the above as a guide.

Since the new server won't be live yet, you should be able to confirm if everything is working properly before you push it live. You'll still have the old one able to be used if the new one fails, so I'm never certain why people claim rsync is a bad idea for someone who does know what they are doing in Linux. Anything you do can be a terrible idea in command line if you don't know Linux.

Of note, if you use rsync and the new server ends up having issues, we won't support the issues created by rsyncing it. Please keep that in mind.
Thanks. Yes, Even I had the same hunch. Doing the WHM Transfer and then rsyncing should work.

I guess I will try this out and post accordingly.

Ill change the local machine hosts files to test it out.

Worst-case: the new server can be cleanly reinstalled.
 

JaredR.

Well-Known Member
Feb 25, 2010
1,834
24
143
Houston, TX
cPanel Access Level
Root Administrator
Using the tools we provide for copying accounts is the only method we can support. As Tristan said, you can often use rsync, but it is best to use it only after using our tools, to make sure "last-minute" changes to data get copied over. However, we cannot provide direct support for any changes made using manual rsync commands.
 

ruzbehraja

Well-Known Member
May 19, 2011
392
11
68
cPanel Access Level
Root Administrator
Completed the migration and IP Switch to retain the old IP.

Besides some expected minor glitches everything was perfect. There was no data loss or data inconsistency.

Let me summarize the steps.
I would like to reiterate for any new readers that the rsync part is solely at your risk. You need to know linux commands to perform some of the functions.
cPanel will NOT provide support for any damage caused by this method.

If you are not comfortable, then DONT try these steps.

Before you start, create backups.

Step 1:
Configured the New server with the same Cpanel / WHM settings as the old one. Some things need to be done manually while some files can be copied over.

Step 2:
Used the WHM Copy Multiple Accounts tool to copy all the accounts over to the new server.

Step 3:
Once the accounts are dumped, you need to keep them synced till the IP is changed.

All the commands are to be performed on the NEW server.

rsync SOURCE(oldserver) DESTINATION(newserver)
What I synced is:
  • Databases
  • Users home folders
  • mailman folders
  • some basic cpanel user files which change often

Although I tried out replication, it worked successfully for a short while and then errors kept cropping up, causing the sync to stop.

I found that copying the WHOLE /var/lib/mysql folder was the most reliable method of transferring sql.
Do note that copying anything less than the WHOLE folder may cause databases to get corrupt.

BEFORE Syncing the databases, you need to ensure that the databases are locked and read only.

This can be achieved by going to the mysql console and typing:
mysql> FLUSH TABLES WITH READ LOCK;
mysql> SET GLOBAL read_only = ON;

Databases were synced with the command:
rsync -avz -e ssh [email protected]:/var/lib/mysql/ /var/lib/mysql
Note that in the above command I have not used the -u switch, since I felt that it was not updating the files properly, causing some databases to get corrupt.

To remove the lock and resume normal database operations you can use:
mysql> SET GLOBAL read_only = OFF;
mysql> UNLOCK TABLES;
Users home folders were synced with:
for user in $(cat tomove) ; do echo "NOW SYNCING: " $user; rsync -avuz --delete -e ssh [email protected]:/home/$user/ /home/$user; done

for user in $(cat tomove) ; do echo "NOW SYNCING: " $user; rsync -avuz --delete -e ssh [email protected]:/home2/$user/ /home/$user; done
Note that in the above command I have used the --delete switch, to delete any files at the destination, which are not present on the source. If you do not put this switch, you will notice that if users on the live(old) server are deleting files, those files will still remain on the new server.

Also note that in my case the old server had 2 disks - home and home2 while the new server only has home.
Hence, both the commands need to be performed in that order only.

This time the -u / --update flag was used to update changed files.

Then i synced the following:
rsync -avuz -e ssh [email protected]:/etc/vdomainaliases /etc/vdomainaliases
rsync -avuz -e ssh [email protected]:/etc/vdomainaliases /etc/vfilters
rsync -avuz -e ssh [email protected]:/etc/vdomainaliases /etc/valiases
rsync -avuz -e ssh [email protected]:/usr/local/cpanel/3rdparty/mailman/ /usr/local/cpanel/3rdparty/mailman
Keep doing these often, till the IP is switched.

Feedback welcome.
 

ruzbehraja

Well-Known Member
May 19, 2011
392
11
68
cPanel Access Level
Root Administrator
Just bumping this thread because I realized that the rsync commands here have a mistake.

These are the right commands:

rsync -avuz -e ssh [email protected]:/etc/vdomainaliases /etc/vdomainaliases
rsync -avuz -e ssh [email protected]:/etc/vfilters /etc/vfilters
rsync -avuz -e ssh [email protected]:/etc/valiases /etc/valiases

I also like to add the --stats tag to see how many files were really updated.

Eg:

rsync -avuz --stats -e ssh [email protected]:/etc/vdomainaliases /etc/vdomainaliases
 
  • Like
Reactions: ElviCities