Restoring cpanel accounts without backups (rm -Rf in root ? Silly You.)
Right, if for some reason someone managed to rm -Rf your root or etc directory,
this may help you to recover a fair amount of your cpanel files.
The process basically involves copying the old files into a new installation of cpanel (same ip as the license from the previous, or just replace the license afterwards)
Then, copying over old mysql files / folders, and using cpanel to package up what files i thinks it can find into a cpmove,
then restoring the cpmove folder back again to pull all the data back into cpanel properly.
THIS IS NOT RECCOMENDED IF YOU ALREADY HAVE ANY CPBACKUP OR CPMOVE FILES.
I accidentally restored one or two of these which turned out to be old onmes, and obviously, all the old data was imported back in and overwritten the new data.
So either restore them using cpanel normally, or move the old cpbackup / move files elsewhere.
cpadduser.sh contents: (DEF$1 is the password, so for user cake, the password would become DEFcake. to manually add passwords when running the script, change DEF$1 to $2.)
---------------------
#!/bin/bash set -u if [ "$1" = "-help" ] then echo "Use: ./cpadduser.sh username" else /scripts/adduser "$1" /home DEF$1 /scripts/pkgacct $1 /scripts/restorepkg --force /home/cpmove-$1.tar.gz chown -R $1:nobody /home/$1 chmod -R 0755 /home/$1/public_html /usr/local/cpanel/bin/rebuild_phpconf 5 none dso 1 /scripts/updateuserdomains exit 0 fi
---------------------
1:
use rysnc from the old home to the new home to preserve as much as possible in terms of permissions etc.
if you want secure rsync across servers, then ensure to use ssh.
e.g below:
/home/oldhomefiles is my files from home directory,
/home/otherfiles is any other files/folders that cpanel uses.
do not worry if you do not have all of the folders/files that i put in /home/otherfiles/ to sync to the new installation, i didnt have all of them either.
rsync -vrplogDtH -e ssh /home/oldhomefiles/* USER@SE.RV.ER.IP:/home rsync -vrplogDtH -e ssh /home/otherfiles/usr/local/cpanel USER@SE.RV.ER.IP:/usr/local rsync -vrplogDtH -e ssh /home/otherfiles/var/lib/mysql USER@SE.RV.ER.IP:/var/lib rsync -vrplogDtH -e ssh /home/otherfiles/var/cpanel USER@SE.RV.ER.IP:/var rsync -vrplogDtH -e ssh /home/otherfiles/usr/share/ssl USER@SE.RV.ER.IP:/usr/share rsync -vrplogDtH -e ssh /home/otherfiles/var/ssl USER@SE.RV.ER.IP:/var rsync -vrplogDtH -e ssh /home/otherfiles/usr/local/cpanel/3rdparty/mailman USER@SE.RV.ER.IP:/usr/local/cpanel/3rdparty rsync -vrplogDtH -e ssh /home/otherfiles/var/log/bandwidth USER@SE.RV.ER.IP:/var/log
rsync -vrplogDtH -e ssh /home/otherfiles/usr/local/frontpage USER@SE.RV.ER.IP:/usr/local rsync -vrplogDtH -e ssh /home/otherfiles/var/spool/cron USER@SE.RV.ER.IP:/var/spool
rsync -vrplogDtH -e ssh /home/otherfiles/usr/local/apache/conf USER@SE.RV.ER.IP:/usr/local/apache rsync -vrplogDtH -e ssh /home/otherfiles/var/named USER@SE.RV.ER.IP:/var rsync -vrplogDtH -e ssh /home/otherfiles/root/.my.cnf USER@SE.RV.ER.IP:/root rsync -vrplogDtH -e ssh /home/otherfiles/etc/httpd/conf/httpd.conf USER@SE.RV.ER.IP:/etc/httpd/conf
cd to the old etc directory:
cd /fhdevsda1/etc
And copy some files from here:
rsync -vrplogDtH -e ssh 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
2:
/scripts/upcp /scripts/updatenow /scripts/sysup /scripts/exim4 /scripts/easyapache /scripts/securetmp /scripts/fixeverything
/scripts/mysqlup --force /usr/local/cpanel/bin/updatephpmyadmin --force /scripts/upcp --force /usr/local/cpanel/cpkeyclt
3:
/scripts/restartsrv httpd /scripts/restartsrv cpanel /scripts/restartsrv mysql /scripts/restartsrv named /scripts/restartsrv exim
4:
use cpadduser.sh to restore accounts.
./cpadduser.sh
passwords can be set by altering the cpadduser script to take a second variable for password.
5:
If permissions are rather broken, try some / all of the following:
any directories requiring 777 (e.g. whmcs templates_c) will have to have the permissions changed back again afterwards.
/scripts/postsuexecinstall /scripts/chownpublichtmls cd /home find -perm 777 -exec chmod 755 {} \; -print find -perm 666 -exec chmod 644 {} \; -print /scripts/fixsuexeccgiscripts
Hopefully this has been of some help to some people, after spending over 19 hours solid trying to restore 120 accounts this is what i managed to come up with.
Not everything may run, some files may not be found etc, but it might get you somewhere.
I take no responsibilty for any dataloss or currupt cpanel accounts from anyone using this,
however with most people when you say "my root drive is broken, how do i restore my cpanel accounts, my backups are old / nonexistent?" they say "You Can't!"
Good luck! If anyone would like to make this process easier, or knows a way to restore account passwords, or a better way for this process, please contact me at support@ganey.co.uk.
Thanks.