**This is an old revision of the document!**
How To Restore a cPanel Server
This article will guide you through the necessary steps to restore your data from a previous cPanel environment that is no longer functional. Examples are when a harddrive is dying and is no longer bootable, when a system is compromised via root, or even if you are moving from an old server to a new one (although the netcat over SSH method is preferred).
- You have a fresh and clean environment onto which you have installed the OS and cPanel. The old drive or partition needs to be local to the server (or available via an NFS mount if you so desire).
- You have the old drive mounted a /olddrive and that it is readable in some fashion. For dying drives this is easier said than done and the drive may fail completely during this process (lots of reads), so be warned!
- The data still exists. If the inode tables have been lost then everything is going to be dumped into /lost+found and this method will not work. If the hacker deleted your data, then you should be glad you had the foresight to maintain another backup medium!
Restoring the data is just a matter of rsync-ing over certain directories and configuration files.
Let's begin by syncing over important /etc/ configuration files:
cd /olddrive/etc/ rsync -avHz user* trueuser* domainips secondarymx domainalias valiases vfiltersexim* backupmxhosts proftpd* pure-ftpd* logrotate.conf passwd* group* *domain* *named* wwwacct.conf cpbackup.conf cpupdate.conf quota.conf shadow* *rndc* ips* ipaddrpool* ssl hosts spammer* skipsmtpcheckhosts relay* localdomains remotedomains my.cnf /etc
/etc/cron.d/if you have custom cron scripts.
Next up is Apache and its configuration:
rsync -avHz /olddrive/usr/local/apache/conf /usr/local/apache rsync -avHz /olddrive/usr/local/apache/modules /usr/local/apache rsync -avHz /olddrive/usr/local/apache/domlogs /usr/local/apache
Next is named (bind). This is only needed if you run your own DNS:
rsync -avHz /olddrive/var/named /var
Next we'll do cPanel and it's related configurations:
rsync -avHz /olddrive/usr/local/cpanel /usr/local
Next up, MySQL databases:
rsync -avHz /olddrive/var/lib/mysql /var/lib
Misc cPanel files and templates:
rsync -avHz /olddrive/var/cpanel /var
Client and server SSL certificates:
rsync -avHz /olddrive/usr/share/ssl /usr/share
User bandwidth data:
rsync -avHz /olddrive/var/log/bandwidth /var/log
Exim's mail queue:
rsync -avHz /olddrive/var/spool/cron /var/spool
Root user MySQL configuration:
rsync -avHz /olddrive/root/.my.cnf /root
Finally, all user data (mail, web files, etc.):
rsync -avHz --exclude=virtfs/ /olddrive/home/* /home
Updates and Cleanup
Because we've changed some cPanel files around and imported a bunch of user data, we'll want to make sure that these changes are picked up:
/scripts/upcp --force /scripts/easyapache /scripts/initquotas /scripts/eximup --force /scripts/mysqlup --force /etc/init.d/cpanel restart /scripts/restartsrv_apache /scripts/restartsrv_exim /scripts/restartsrv_named
Since we copied over the contents of
/var/cpanel, your previously saved Apache/PHP build options will be retained when
/scripts/easyapache is run above (select Previously Saved Config).
Since this is a “new” install of cPanel, you'll have to run through the WHM Setup Wizard once again upon first login. Just enter the settings as you prefer them/as they were before. If you do not recall some of your previous settings such as nameservers, hostname, or contact email, they can all be found in /etc/wwwacct.conf.
- This was last tested to work as of cPanel/WHM 11.26. Newer versions might change the functionality of scripts and/or add additional configuration files.