Recovering the 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 the HDD is accidentally destroyed, then we can get a new HDD and a new operating system from data center and restore data on a new drive by using the following method without lose of data. This concept can be used to migrate cPanel Servers from destroyed HDD to new HDD.

1) Get the partitions from both the drives with:

# fdisk -l

2)First check, to see if there are any drives mounted:

# df -h

3) Let us assume that /dev/hdb3 is our CRASHED old drive and it is mounted as /mnt/old (Yours can be different) skip this step. If not mounted, mount the crashed disk as like below:

# mount /dev/hdb3 /oldHD

4) Now that the drive is mounted you can try to browse files:

# ls /oldHD/home

5) Now ready to move the data from old drive to new drive.

Run these rsync commands to move everything:

# 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 /oldHD/etc

# 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 the below scripts,

Updating software and restarting services:

# /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 fix everything. 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 or try with the below command.

# yum install opensshd-server opensshd opensshd-client
# service sshd restart

And Restart other services as:

# /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 to NEW HDD within server.

Note: If the above steps not worked, Please check again by using the following steps.

These commands will allow you to manually migrate all customer data and configs from an old primary drive installed as a slave

* source drive should be mounted to /mnt/oldprimary
* run chkrootkit to make sure you don’t copy back infected files.. chkrootkit — locally checks for signs of a rootkit

now we can start copying back data from the old drive

# rsync -vrplogDtH /mnt/oldprimary/usr/local/apache/conf /usr/local/apache
# rsync -vrplogDtH /mnt/oldprimary/var/named /var
# rsync -vrplogDtH /mnt/oldprimary/home/* /home
# rsync -vrplogDtH /mnt/oldprimary/usr/local/cpanel /usr/local
# rsync -vrplogDtH /mnt/oldprimary/var/lib/mysql /var/lib
# rsync -vrplogDtH /mnt/oldprimary/var/cpanel /var

# rsync -vrplogDtH /mnt/oldprimary/usr/share/ssl /usr/share
# rsync -vrplogDtH /mnt/oldprimary/var/ssl /var
# rsync -vrplogDtH /mnt/oldprimary/usr/local/cpanel/3rdparty/mailman /usr/local/cpanel/3rdparty
# rsync -vrplogDtH /mnt/oldprimary/var/log/bandwidth /var/log
# rsync -vrplogDtH /mnt/oldprimary/usr/local/frontpage /usr/local
# rsync -vrplogDtH /mnt/oldprimary/var/spool/cron /var/spool
# rsync -vrplogDtH /mnt/oldprimary/root/.my.cnf /root
# rsync -vrplogDtH /mnt/oldprimary/etc/httpd/conf/httpd.conf /etc/httpd/conf
# rsync -vrplogDtH /mnt/oldprimary/etc/sysconfig/network /etc/sysconfig

then change to the old etc, and execute all on one line …

# cd /mnt/oldprimary/etc
# 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

Update cpanel afterwards
/scripts/upcp
/scripts/updatenow
/scripts/sysup
/scripts/fixeverything

it worked very nicely, and in matter of 4 – 5 hours server was running again. Though doing this using cpanel backups would have taken about 24 hours.

Leave a comment