The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Restoring cpanel accounts without backups (rm -Rf in root ? Silly You.)

Discussion in 'General Discussion' started by FuelledHosting, Sep 21, 2011.

  1. FuelledHosting

    FuelledHosting Registered

    Joined:
    Sep 21, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Right, if for some reason someone managed to rm -Rf your root or etc directory,
    this may help you to restore a fair amount of your cpanel files. back into cpanel.

    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.)

    Code:
    ---------------------
    
    #!/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.

    Code:
    rsync -vrplogDtH -e ssh /home/oldhomefiles/* USER@SE.RV.ER.IP:/homersync -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:
    Code:
    cd /otherfiles/etc
    And copy some files from here:
    Code:
    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:
    Code:
    
    /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:

    Code:
    /scripts/restartsrv httpd
    /scripts/restartsrv cpanel
    /scripts/restartsrv mysql
    /scripts/restartsrv named
    /scripts/restartsrv exim
    4:
    copy cpadduser(above) into a new file (cpadduser.sh)
    use cpadduser.sh to restore accounts.
    Code:
    ./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.
    Code:
    [I]
    /scripts/postsuexecinstall
    /scripts/chownpublichtmls
    cd /home find -perm 777 -exec chmod 755 {} \; -print
    find -perm 666 -exec chmod 644 {} \; -print
    /scripts/fixsuexeccgiscripts[/I]


    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.
     
Loading...

Share This Page