UK WEB HOSTING FORUM FOR DISCUSSION ON WEB HOSTING SERVICE AND SUPPORT
LINUX HOSTING WINDOWS HOSTING PACKAGES SHOPPING CART OSCOMMERCE ZEN CART AGORA
ECOMMERCE HOSTING ASP MSSQL FRONTPAGE HOSTING PHP MYSQL HOSTING DISCUSSION FORUM
CPANEL RESELLER HOSTING DEDICATED SERVER VPS HOSTING PLESK VIRTUOZZO
Quick Search
Your forum announcement here!

  UK Web Hosting | Dedicated Server Windows and Linux VPS Forum > Technical Support > Tutorials / How to?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 22-07-2007, 15:00
eUK-Martin's Avatar
Windows System Administrator
 
Join Date: Nov 2005
Location: Earth
Posts: 385
Default Recovering the cpanel Server from Crashed HDD With Rsync

Recovering cPanel Server from Crashed HDD With Rsync :

Rsync is another very powerful command that is used to sync 2 directories between servers and only transfer the new files to the server.This is a great method for backing up the data as it is low on bandwidth and it is also commonly used to keep clustered servers working together. The ending slashes are very important when using rsync. If you are not familiar with how it works simply always make sure to have an ending slash on both the source and the destination and it should be fine.

In case if we fail or accidentally destroyed our HDD then we can get a new HDD and a new operating system from datacenter and restore data on a new drive. This concept can be used to migrate cPanel Servers from one server to another Server without loosing any data or any sort of downtime for websites hosted on the server.

This is how it will work:

1) Get the partitions from both the drives with:
Code:
# fdisk -l
2)First check to see if there are any drives mounted, with:
Code:
# df -h
2) Let us assume that /dev/hdb3 is our CRASHED old drive and it is mounted as /mnt/old (Yours can be different). But keep in mind that you need to know the mount point of the backup drive before we proceed further with the steps below:

Let us mount the CRASHED HDD if not already mounted, with:
Code:
# mount /dev/hdb3 /oldHD
3) Now that the drive is mounted you can browse files, with:
Code:
# ls /oldHD/home
4) We are all set to move our data over to the new drive.

Run these rsync commands to move everything over:
Code:
rsync -vrplogDtH /oldHD/usr/local/apache/conf /usr/local/apache
rsync -vrplogDtH /oldHD/var/named /var
rsync -vrplogDtH /oldHD/home/* /home
rsync -vrplogDtH /oldHD/usr/local/cpanel /usr/local
rsync -vrplogDtH /oldHD/var/lib/mysql /var/lib
rsync -vrplogDtH /oldHD/var/cpanel /var
rsync -vrplogDtH /oldHD/usr/share/ssl /usr/share
rsync -vrplogDtH /oldHD/var/ssl /var
rsync -vrplogDtH /oldHD/usr/local/cpanel/3rdparty/mailman /usr/local/cpanel/3rdparty
rsync -vrplogDtH /oldHD/var/log/bandwidth /var/log
rsync -vrplogDtH /oldHD/usr/local/frontpage /usr/local
rsync -vrplogDtH /oldHD/var/spool/cron /var/spool
rsync -vrplogDtH /oldHD/root/.my.cnf /root
rsync -vrplogDtH /oldHD/etc/httpd/conf/httpd.conf /etc/httpd/conf
cd to the old etc directory:
Code:
#cd /oldHD/etc
And copy some files from here:

Code:
#rsync -vrplogDtH secondarymx domainalias valiases vfilters exim* proftpd* pure-ftpd* passwd* group* *domain* *named* wwwacct.conf cpupdate.conf quota.conf shadow* *rndc* ips* ipaddrpool* ssl hosts /etc
6)We are done with the copying of all the files and cPanel should start recognizing all the old users and their files. But after we do all this, It is highly suggest that you run all updates, and run cpanel fix scripts i.e

Updating software and restarting services :
Code:
#/scripts/upcp
#/scripts/updatenow
#/scripts/sysup
#/scripts/exim4
#/scripts/easyapache
#/scripts/securetmp
# /scripts/fixeverything
7)This is needed to update cpanel information. Please note, sshd might fail and not start after running fixeverything. You have to login to whm, and go to the rpm installer and "FORCE" install opensshd-server, opensshd, opensshd-client and then restart sshd from whm.

Restarting services as :

Code:
#/scripts/restartsrv httpd
#/scripts/restartsrv cpanel
#/scripts/restartsrv mysql
#/scripts/restartsrv named
#/scripts/restartsrv exim
That is all what we need to recover data from a CRASHED HDD.

Same procedure can be used to Migrate one server to another server without any data loss or downtime. Following steps will be different in this case and for this particular requirement you will need to go through following configurations :-

1. Share SSH keys between both servers ( only if you have full control of both servers ). To share SSH keys you will first need to generate keys on both servers with following command :-

Code:
#ssh-keygen -t rsa -b 1024
run above command only if you dont have any information in /root/.ssh/ directory. Once the keys are generated you will see following files in the directory :-
id_rsa id_rsa.pub known_hosts

now to share the keys you need to copy content of id_rsa.pub file and create a new file called authorized_keys in same directory on other server. paste content of id_rsa.pub of server 1 in server2 and server2 in server1 authorized_keys. Sharing SSH keys in this way will allow you to sync data between both servers without any sort of password authentication. You will need to create this file ( authorized_keys ) as it wont be there by default.

browse to /etc directory on the source server and run following command from that directory :-
Code:
#rsync -vrplogDtH secondarymx domainalias valiases vfilters exim* proftpd* pure-ftpd* passwd* group* *domain* *named* wwwacct.conf cpupdate.conf quota.conf shadow* *rndc* ips* ipaddrpool* ssl hosts root@10.10.10.2:/etc
( 10.10.10.2 is assumed as IP of the new server to which we are moving data )

now we need to transfer everything else.
Code:
rsync -vrplogDtH /usr/local/apache/conf root@10.10.10.2:/usr/local/apache
rsync -vrplogDtH /var/named root@10.10.10.2:/var
rsync -vrplogDtH /home/* root@10.10.10.2:/home
rsync -vrplogDtH /usr/local/cpanel root@10.10.10.2:/usr/local
rsync -vrplogDtH /var/lib/mysql root@10.10.10.2:/var/lib
rsync -vrplogDtH /var/cpanel root@10.10.10.2:/var
rsync -vrplogDtH /usr/share/ssl root@10.10.10.2:/usr/share
rsync -vrplogDtH /var/ssl root@10.10.10.2:/var
rsync -vrplogDtH /usr/local/cpanel/3rdparty/mailman root@10.10.10.2:/usr/local/cpanel/3rdparty
rsync -vrplogDtH /var/log/bandwidth root@10.10.10.2:/var/log
rsync -vrplogDtH /usr/local/frontpage root@10.10.10.2:/usr/local
rsync -vrplogDtH /var/spool/cron root@10.10.10.2:/var/spool
rsync -vrplogDtH /root/.my.cnf root@10.10.10.2:/root
rsync -vrplogDtH /etc/httpd/conf/httpd.conf root@10.10.10.2:/etc/httpd/conf
one more extra thing which needs to be done in this case is mass replace command for changing IP address in zone files and httpd.conf. Here's a command to help you do it in few seconds :-
Code:
replace 10.10.10.1 10.10.10.2 -- /var/named/*.db
replace 10.10.10.1 10.10.10.2 -- /usr/local/apache/conf/httpd.conf
10.10.10.1 is assumed as IP of source server
10.10.10.2 is assumed as IP of new destination server which will now run your websites.

If you run this mass replace command on the source server as well then all websites will start pointing to the new server immediately which will ensure 0 downtime for your websites. This concept can be used for a VPS as well.
__________________
Martin
Windows System Admin.


Windows VPS Hosting - Windows Dedicated Server - Web Hosting Tutorials

Email :: windows @ eUKhost.com AND support @ eUKhost.com
Reply With Quote
  #2 (permalink)  
Old 22-07-2007, 21:37
eUKhost.com's Avatar
Chief Marketing Officer
 
Join Date: Sep 2005
Posts: 4,261
Send a message via AIM to eUKhost.com Send a message via MSN to eUKhost.com
Default

Thanks Martin

Great information for cPanel Server Migration. You have disclosed everything that we do for migrations
__________________
UK Web Hosting || Business Hosting || eUKhost Knowledgebase
Toll Free : 0808 262 0255 || MSN : mark @ eukhost.com || AIM : eukmark
A bunch of Sheep led by a Lion is better than a bunch of Lions led by a Sheep.
__________________________________________________

Great Opportunity :: Join our Affiliate Program for FREE and earn 20% commission on each referral.
Reply With Quote
  #3 (permalink)  
Old 23-07-2007, 11:45
Member
 
Join Date: Dec 2006
Location: UK
Posts: 92
Default

Fantastic tutorial!

Couple of questions though ... Would it be possible to use SSH keys which use passwords? And would it be possible to use different ports (than the standard port 22) for SSH?
Reply With Quote
  #4 (permalink)  
Old 23-07-2007, 14:29
eUKhost.com's Avatar
Chief Marketing Officer
 
Join Date: Sep 2005
Posts: 4,261
Send a message via AIM to eUKhost.com Send a message via MSN to eUKhost.com
Default

If you wish to enter password manually on execution of each rsync command then you should not share the SSH keys between both servers. You can use Rsync as following to transfer data with SSH port of destination server being different :-

rsync -vrplogDtH -e "ssh -p 12345" /usr/local/apache/conf root@10.10.10.2:/usr/local/apache

where 12345 is SSH port of destination server.
10.10.10.2 is IP of destination server
/usr/local/apache/conf is directory on local server which will be moved on destination server in /usr/local/apache
__________________
UK Web Hosting || Business Hosting || eUKhost Knowledgebase
Toll Free : 0808 262 0255 || MSN : mark @ eukhost.com || AIM : eukmark
A bunch of Sheep led by a Lion is better than a bunch of Lions led by a Sheep.
__________________________________________________

Great Opportunity :: Join our Affiliate Program for FREE and earn 20% commission on each referral.
Reply With Quote
  #5 (permalink)  
Old 24-07-2007, 13:05
DPS Computing's Avatar
Premium Member
 
Join Date: Apr 2007
Location: Manchester, United Kingdom
Posts: 4,472
Send a message via ICQ to DPS Computing Send a message via AIM to DPS Computing Send a message via MSN to DPS Computing Send a message via Yahoo to DPS Computing Send a message via Skype™ to DPS Computing
Default

Yes thanks for that tutorial Martin - it is extreamely comprehensive!!

How long did it take you to write it?
__________________
David Smith
DPS Computing
http://www.dpscomputing.com (Computing, Reviews, News) - New site / new polls / new stories! With many more to follow!
NEW LAUNCH! http://djdavid.dpscomputing.com (My DJ Website)
NEW LAUNCH! http://davidsmith.dpscomputing.com (My Personal Website)
Reply With Quote
  #6 (permalink)  
Old 24-07-2007, 14:05
eUKhost.com's Avatar
Chief Marketing Officer
 
Join Date: Sep 2005
Posts: 4,261
Send a message via AIM to eUKhost.com Send a message via MSN to eUKhost.com
Default

Quote:
Originally Posted by DPS Computing View Post
Yes thanks for that tutorial Martin - it is extreamely comprehensive!!

How long did it take you to write it?
it took 30 mins for me to edit and add few more things in the original post to include remote server migration process.
__________________
UK Web Hosting || Business Hosting || eUKhost Knowledgebase
Toll Free : 0808 262 0255 || MSN : mark @ eukhost.com || AIM : eukmark
A bunch of Sheep led by a Lion is better than a bunch of Lions led by a Sheep.
__________________________________________________

Great Opportunity :: Join our Affiliate Program for FREE and earn 20% commission on each referral.
Reply With Quote
  #7 (permalink)  
Old 24-07-2007, 14:12
DPS Computing's Avatar
Premium Member
 
Join Date: Apr 2007
Location: Manchester, United Kingdom
Posts: 4,472
Send a message via ICQ to DPS Computing Send a message via AIM to DPS Computing Send a message via MSN to DPS Computing Send a message via Yahoo to DPS Computing Send a message via Skype™ to DPS Computing
Default

Quote:
Originally Posted by eUKhost.com View Post
it took 30 mins for me to edit and add few more things in the original post to include remote server migration process.
Wow, so 30 mins was just the editing time then! Must have taken an hour at least to write then .
__________________
David Smith
DPS Computing
http://www.dpscomputing.com (Computing, Reviews, News) - New site / new polls / new stories! With many more to follow!
NEW LAUNCH! http://djdavid.dpscomputing.com (My DJ Website)
NEW LAUNCH! http://davidsmith.dpscomputing.com (My Personal Website)
Reply With Quote
  #8 (permalink)  
Old 26-07-2007, 01:23
eUK-Martin's Avatar
Windows System Administrator
 
Join Date: Nov 2005
Location: Earth
Posts: 385
Default

Quote:
Originally Posted by eUKhost.com View Post
it took 30 mins for me to edit and add few more things in the original post to include remote server migration process.
Wow.. I din't realise that the changes were made in my post. Thanks Mr. Mark . This adds alot of weight to the original post and it will be very helpful indeed.
__________________
Martin
Windows System Admin.


Windows VPS Hosting - Windows Dedicated Server - Web Hosting Tutorials

Email :: windows @ eUKhost.com AND support @ eUKhost.com
Reply With Quote
  #9 (permalink)  
Old 27-07-2007, 12:37
DPS Computing's Avatar
Premium Member
 
Join Date: Apr 2007
Location: Manchester, United Kingdom
Posts: 4,472
Send a message via ICQ to DPS Computing Send a message via AIM to DPS Computing Send a message via MSN to DPS Computing Send a message via Yahoo to DPS Computing Send a message via Skype™ to DPS Computing
Default

Quote:
Originally Posted by eUK-Martin View Post
Wow.. I din't realise that the changes were made in my post. Thanks Mr. Mark . This adds alot of weight to the original post and it will be very helpful indeed.
Yes, it didn't write "Last Edit by:" underneath it - Mark must have an invisible footprint .
__________________
David Smith
DPS Computing
http://www.dpscomputing.com (Computing, Reviews, News) - New site / new polls / new stories! With many more to follow!
NEW LAUNCH! http://djdavid.dpscomputing.com (My DJ Website)
NEW LAUNCH! http://davidsmith.dpscomputing.com (My Personal Website)
Reply With Quote
  #10 (permalink)  
Old 17-03-2008, 22:54
eUKhost.com's Avatar
Chief Marketing Officer
 
Join Date: Sep 2005
Posts: 4,261
Send a message via AIM to eUKhost.com Send a message via MSN to eUKhost.com
Default

VPS and Dedicated Server customers should go through this article if they have basic knowledge of Linux. We use this process everyday as there are some customers who get their old servers migrated on our new servers, some VPS's are migrated from old nodes to new nodes or some or the other server restoration process has to be completed using Rsync.

We've started using Rsync for our windows server backups as well so knowledge of Rsync is really helpful if you wish to make your hosting business successful
__________________
UK Web Hosting || Business Hosting || eUKhost Knowledgebase
Toll Free : 0808 262 0255 || MSN : mark @ eukhost.com || AIM : eukmark
A bunch of Sheep led by a Lion is better than a bunch of Lions led by a Sheep.
__________________________________________________

Great Opportunity :: Join our Affiliate Program for FREE and earn 20% commission on each referral.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:25.

 

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by Web Hosting 3.1.0
Copyright © 2001-2008, eUKhost.com. All rights reserved.

 
Site Map

knowledgebase articles

popular blog categories