Restore cPanel on dedicated server (cp,rsync)Rsync is another very powerful command that is used to synchronise 2 directories between servers and only transfer the new files to the server. This is a great method for backing up 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, always make sure to have an ending slash on both the source and the destination and it should be fine.
In case we fail or accidentally destroy our HDD then we can get a new HDD and operating system from the datacentre and restore the data on a new drive. This concept can be used to migrate cPanel Servers from one server to another without loosing any data or creating any sort of downtime for websites hosted on the server.
This is how it will work:
1) Get the partitions from both the drives with:
- Code: Select all
fdisk -l
2) Check to see if there are any drives mounted with:
- Code: Select all
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), but keep in mind that you need to know the mount point of the backup drive before we proceed further with the steps below.
Let us mount the CRASHED HDD if not already mounted with:
- Code: Select all
mount /dev/hdb3 /oldHD
4) Now that the drive is mounted you can browse any files with:
- Code: Select all
ls -la /oldHD/home
5) We are all set to move our data over to the new drive:
Run these rSync commands to move everything over:
- Code: Select all
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 to the old etc directory:
- Code: Select all
cd /oldHD/etc
And copy some files from here:
- Code: Select all
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 suggested that you run all updates, and run the cPanel fix scripts i.e:
Updating software and restarting services:
- Code: Select all
/scripts/upcp --force
/scripts/easyapache
/scripts/securetmp
That is all we need to recover data from a CRASHED HDD.
Procedure to Migrate live cPanel Server to a new cpanel serverSame procedure can be used to migrate one server to another without any data loss or downtime. The following steps will be different in this case and for this particular requirement you will need to go through the following configurations.
1) Share SSH keys between both servers (only if you have full control of both servers). To share SSH keys you will first need to generate keys on both servers with following command:
- Code: Select all
ssh-keygen -t rsa -b 1024
Run above command only if you dont have any information in ‘/root/.ssh/ directory’. Once the keys are generated you will see the following files in the directory:
id_rsa id_rsa.pub known_hosts
Now to share the keys you need to copy the contents of id_rsa.pub file and create a new file called authorized_keys in the same directory on the other server. Paste the contents of id_rsa.pub of server1 in server2 and server2 in server1 authorized_keys. Sharing SSH keys in this way will allow you to sync data between both servers without any sort of password authentication. You will need to create this file (authorized_keys) as it won’t be there by default.
Browse to the ‘/etc’ directory on the source server and run following command from that directory:
- Code: Select all
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 [email protected]:/etc
(10.10.10.2 is assumed as the IP of the new server to which we are moving the data.)
Now we need to transfer everything else.
- Code: Select all
rsync -vrplogDtH /usr/local/apache/conf [email protected]:/usr/local/apache
rsync -vrplogDtH /var/named [email protected]:/var
rsync -vrplogDtH /home/* [email protected]:/home
rsync -vrplogDtH /usr/local/cpanel [email protected]:/usr/local
rsync -vrplogDtH /var/lib/mysql [email protected]:/var/lib
rsync -vrplogDtH /var/cpanel [email protected]:/var
rsync -vrplogDtH /usr/share/ssl [email protected]:/usr/share
rsync -vrplogDtH /var/ssl [email protected]:/var
rsync -vrplogDtH /usr/local/cpanel/3rdparty/mailman [email protected]:/usr/local/cpanel/3rdparty
rsync -vrplogDtH /var/log/bandwidth [email protected]:/var/log
rsync -vrplogDtH /usr/local/frontpage [email protected]:/usr/local
rsync -vrplogDtH /var/spool/cron [email protected]:/var/spool
rsync -vrplogDtH /root/.my.cnf [email protected]:/root
rsync -vrplogDtH /etc/httpd/conf/httpd.conf [email protected]:/etc/httpd/conf
One more thing which needs to be done in this case is a mass replace command for changing the IP address in the zone files and httpd.conf. Here’s a command to help you do it in a few seconds:
- Code: Select all
replace 10.10.10.1 10.10.10.2 — /var/named/*.db
replace 10.10.10.1 10.10.10.2 — /usr/local/apache/conf/httpd.conf
10.10.10.1 is assumed as the IP of source server.
10.10.10.2 is assumed as the IP of the new destination server which will now run your websites.
If you run this mass replace command on the source server as well then all the websites will start pointing to the new server immediately which will ensure no downtime for your websites. This concept can be used for a VPS as well.