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
website hostings hosted on the server.
This is how it will work:
1) Get the partitions from both the drives with:
2)First check to see if there are any drives mounted, with:
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:
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:
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
website hostings.
If you run this mass replace command on the source server as well then all
website hostings will start pointing to the new server immediately which will ensure
0 downtime for your
website hostings. This concept can be used for a
VPS Hosting as well.