Replicate server for disaster recovery?

Gojko

Well-Known Member
Nov 24, 2014
98
7
8
35
Macedonia
cPanel Access Level
Root Administrator
Hello. Is it possible to replica the whole server?
Example:
Working server1
Backup server2

I use rsync to "/" the whole server 1 to server2
I replace hardware hdd or the whole server then i use rsync from server2 to server1 to back all files.
Is this scenario is possible?
If is not how it is possible to make replica server?
 

cPanelLauren

Forums Analyst II
Staff member
Nov 14, 2017
7,090
559
263
Houston
cPanel Access Level
DataCenter Provider
Hello,


There is a wealth of information and requests for this in the forums, some examples of that might be found in the following threads:


I'd also encourage you to vote on the feature requests for this here:

 

Jcats

Well-Known Member
PartnerNOC
May 25, 2011
741
135
168
32
New Jersey
www.bigscoots.com
cPanel Access Level
DataCenter Provider
Here is a script I wrote for a customer, happy to share, it works good but would encourage you to look it over to ensure it will work for you.

You would run this script on the Backup server which is considered the 'local' server in the script, remote server is the live server.

Bash:
#!/bin/bash

# BigScoots - cpanel fail over sync



liveserver=192.168.1.196

sshport=2222



# Remove any accounts from the failover server that no longer reside on the live server.

rm -f /tmp/remoteusers.txt /tmp/localusers.txt

ssh -p "$sshport" "$liveserver" "whmapi1 listaccts" |grep user: |awk '{print $2}' >> /tmp/remoteusers.txt

whmapi1 listaccts |grep user: |awk '{print $2}' >> /tmp/localusers.txt

for i in $(grep -Fxv -f /tmp/remoteusers.txt /tmp/localusers.txt)

do

/scripts/removeacct --force "$i"

  done



rm -f /tmp/remoteusers.txt /tmp/localusers.txt

ssh -p "$sshport" "$liveserver" "whmapi1 listaccts" |grep user: |awk '{print $2}' >> /tmp/remoteusers.txt

whmapi1 listaccts |grep user: |awk '{print $2}' >> /tmp/localusers.txt



xferid=$(whmapi1 create_remote_root_transfer_session remote_server_type=cpanel host="$liveserver" port="$sshport" user=root sshkey_name=id_rsa transfer_threads=10 restore_threads=10 unrestricted_restore=1 copy_reseller_privs=0 compressed=0 unencrypted=0 low_priority=0 |grep transfer_session_id: | awk '{print $2}')



for cpuser in $(grep -Fxv -f /tmp/localusers.txt /tmp/remoteusers.txt)

do

    whmapi1 enqueue_transfer_item transfer_session_id="$xferid" module=AccountRemoteRoot user="$cpuser" localuser="$cpuser" force=1 overwrite_sameowner_dbs=1 overwrite_sameowner_dbusers=1 skiphomedir=1 skipbwdata=1

done



for cpuser in $(ssh -p "$sshport" "$liveserver" "whmapi1 listaccts" |grep user: |awk '{print $2}') ; do

    whmapi1 enqueue_transfer_item transfer_session_id="$xferid" module=AccountRemoteRoot user="$cpuser" localuser="$cpuser" force=1 overwrite_sameowner_dbs=1 overwrite_sameowner_dbusers=1 skiphomedir=1 skipbwdata=1 skipaccount=1



done



    whmapi1 start_transfer_session transfer_session_id="$xferid"



rsync -a --exclude 'virtfs' --exclude 'error_log' --exclude 'cpanelsolr' --delete -e "ssh -p "$sshport"" "$liveserver":/home/ /home/
 
Last edited:
  • Like
Reactions: cPanelLauren

Gojko

Well-Known Member
Nov 24, 2014
98
7
8
35
Macedonia
cPanel Access Level
Root Administrator
Hello, thanks for reply. BUT this is sync for ACCOUNTS only i need for server configuration (cPanel configuration, PHP extensions, EasyApache, DNS)?

all what i read in that forums is that no solution for config file only static files rsync and featured request that is old couple years with no progression

for accounts i have script that backup and upload to remote server, but that is >backup< and if the whole server goes down, to get back 100 accounts from backup that could be a problem and also there is a problem with cPanel configuration, when i install on new server and bring back all 100 accounts some of them still will be offline because use some PHP extension or something else from configuration, that is why i need SERVER clone not just backup accounts

any solution for this kind of scenario?