Restoring cPanel from disk
From SuperbHosting.net Support Wiki
This article explains how to restore cPanel and sites from a mounted slave disk (crash/hack/bad kernel).
Warning: This is not to be done by inexperienced administrators. Bad things could happen. You may wish to contact technical support and request that they do this on your behalf on a billable basis. The only reason this may not work is if there are customizations made to software managed by cPanel that cannot be re-instated, or by copying the configuration, or MySQL is not working properly before it is attempted.
Sometimes if you get hacked or boot with a bad kernel, you need to have technical support mount your old drive, and install a new one with a fresh installation of Linux. The operation detailed below works on FreeBSD, Redhat, Fedora and CentOS. No other Linux distributions have been tested. You cannot restore a Linux cPanel installation to a FreeBSD cPanel installation.
Contents |
Before you start
Make sure MySQL is at least running. Even if you can't login as the root user it must be running at least. To check this:
# ps auxww | grep mysqld
If it is not running, try to start it and then check it again.
# service mysql start
Update your kernel
1. First things first, let's make sure you have an updated kernel, we will do it with up2date for ease of use.
# up2date -f kernel
2. Check the grub.conf /or lilo config to ensure the settings are right. (if using lilo run this command aswell /sbin/lilo -v -v and check for errors)
3. Now reboot the server.
# shutdown -r now
Mount the Backup/Old Drive
First check to see if there are any drives mounted.
# df -h
You should get something simular to this if it isn't mounted yet:
[root@localhost root]# df -h Filesystem Size Used Avail Use% Mounted on /dev/hda2 37G 1.4G 33G 4% / /dev/hda1 101M 7.7M 88M 9% /boot none 125M 0 125M 0% /dev/shm [root@localhost root]#
If it is mounted you will see something like this:
-bash-2.05b# df -h Filesystem Size Used Avail Use% Mounted on /dev/hda3 53G 31G 20G 62% / /dev/hda1 99M 14M 80M 15% /boot none 248M 0 248M 0% /dev/shm /dev/hdc3 53G 31G 20G 61% /mnt/old -bash-2.05b#
As you can see hdc3 is the old drive, and it is mounted as /mnt/old. Yours will be different possibly. But keep in mind you need to know the mount point for the backup drive for the following steps. It is recommended that you use the same mount point if possible so copy/paste from this document is easier.
Let's mount if not already mounted (this command will give you a list of all the drives connected and active)
# fdisk -l
Check for additional drives, in this tutorial we will use /dev/hdc3.
# mount /dev/hdb3 /mnt/old
Now that the drive is mounted you can browse files like:
# ls /mnt/old/home
Copy the data
Do these commands one by one, don't paste them all into your terminal since you may miss a serious error if data is missing or there is a problem with the disk.
rsync -vrplogDtH /mnt/old/usr/local/apache/conf /usr/local/apache rsync -vrplogDtH /mnt/old/var/named /var rsync -vrplogDtH /mnt/old/home/* /home rsync -vrplogDtH /mnt/old/usr/local/cpanel /usr/local rsync -vrplogDtH /mnt/old/var/lib/mysql /var/lib rsync -vrplogDtH /mnt/old/var/cpanel /var rsync -vrplogDtH /mnt/old/usr/share/ssl /usr/share rsync -vrplogDtH /mnt/old/var/ssl /var rsync -vrplogDtH /mnt/old/usr/local/cpanel/3rdparty/mailman /usr/local/cpanel/3rdparty rsync -vrplogDtH /mnt/old/var/log/bandwidth /var/log rsync -vrplogDtH /mnt/old/usr/local/frontpage /usr/local rsync -vrplogDtH /mnt/old/var/spool/cron /var/spool
The next step is to get some important files from etc.
cd /mnt/old/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 /etc
Now is when you must change your password for root.
# passwd root
Updating and restarting services
Run the following cPanel commands to update and fix any configuration and versions that might be not quite right.
/scripts/upcp /scripts/updatenow /scripts/sysup /scripts/fixeverything /scripts/securetmp
This is needed to update cPanel information. Please note, sshd might fail and not start after running fixeverything. To fix it again you have to login to whm, go to the rpm installer and "FORCE" install opensshd-server, opensshd, opensshd-client and then restart sshd from whm.
Restart the services
Run these to restart various services. Some of these might not work depending on the version of cPanel you have. Do not worry.
/scripts/restartsrv httpd /scripts/restartsrv cpanel /scripts/restartsrv mysql /scripts/restartsrv named /scripts/restartsrv exim
After you are pleased that everything is working, reboot the entire server or request a supervised reboot from staff through myCP. Do not use the Reboot option from the main myCP menu. You must open a ticket to request a supervised reboot.
# shutdown -r now
If you don't know what all of the above means, please contact technical support via MyCP as soon as possible. Superb Internet cannot be held responsible if this process does not restore your server to its original state or causes more problems than it solves.
