Clone Server-A to Server-B

SeanLee

Well-Known Member
May 23, 2004
52
1
156
I have some very old server hardware that runs my cPanel instance, and it's giving me major problems. I will be installing a new server this weekend. What is the proper proceedure for cloning an entire cpanel server? I don't mean just the accounts, I mean all the DNS, mail, http etc info as well. I don't want to lose anything. This server is also my primary and secondary nameserver for all my customer domains.

-Should I use Ghost to image the drive?
-Should I install the OS & cPanel on the new server, and copy over specific directories?
-Should I do something else?

All comments appreciated.

Thanks,

Sean
 

cyon

Well-Known Member
PartnerNOC
Jan 15, 2003
314
0
241
I wouldn't recommend to clone your harddrive 1:1, because you have different hardware installed and so on.
I would install a fresh OS, then install cPanel, then do all settings like you have on your current machine (same dns settings and so on.)
Then I would use the account copy function and copy all accounts over.
DNS entries, httpd.conf entries etc will be created on the new machine during the copy process.
 

SeanLee

Well-Known Member
May 23, 2004
52
1
156
How am I to know which files need to be copied in order to duplicate my system though? I mean, what if I forget somebody's SSL key or something? There is no list of directories that need to be copied anywhere? I find it hard to believe that I am the only person that has run into a problem before where a component has died and you need to build a new server!
 

weaver

Active Member
Jan 19, 2005
30
0
156
Hi -

I would take the same road as cyon. I have done this several times as I evolve my hosting platforms and other than a few hicups such as losing a whm package or a lost dns zone I have had not had any problems at all!

Cloning the drive and OS would be a VERY bad idea in my opinion and the account importation feature will definitely cause you much less aggro as apposed to cloning. If there are any account importation problems such as a "missing ssl key" as you suggest then I'm sure these hicups will be nothing that can't be fixed by a competent system administrator in which I must stress that cPanel/WHM is no substitute.

Good luck!!
 

DigitalN

Well-Known Member
Sep 23, 2004
419
1
168
Hello,

If you run cPanel backups, you will see

/$backup/cpbackup/daily/files

/$backup/cpbackup/daily/dirs

These 2 directories contain all the config files required to restore the accounts onto another server, once cpanel has been installed onto it.

Simply untarring those files and dirs or rsync them directly from the root file system, and use rsync to transfer them to the new server.
This is much quicker and less errors than using the whm account copies.

The users /home files can be extracted from /$backup/cpbackup/daily/user.tar.gz or directly from /home of course :)

Then copy the $user/homedir to /home/$user

I have written and posted scripts to do this on this forum :)

Will you be using the same IP's on the new box?
 

SeanLee

Well-Known Member
May 23, 2004
52
1
156
DigitalN said:
Hello,

If you run cPanel backups, you will see

/$backup/cpbackup/daily/files

/$backup/cpbackup/daily/dirs

These 2 directories contain all the config files required to restore the accounts onto another server, once cpanel has been installed onto it.

Simply untarring those files and dirs or rsync them directly from the root file system, and use rsync to transfer them to the new server.
This is much quicker and less errors than using the whm account copies.

The users /home files can be extracted from /$backup/cpbackup/daily/user.tar.gz or directly from /home of course :)

Then copy the $user/homedir to /home/$user

I have written and posted scripts to do this on this forum :)

Will you be using the same IP's on the new box?

Yes, I will be using the same IP. It's just odd to me that there isn't a already a defined process that everyone can follow. Thanks and I will look for your scripts :)
 

DigitalN

Well-Known Member
Sep 23, 2004
419
1
168
You should be able to modify this for your needs - I usually have 2 machines online, the new machine up on an IP that isn't used on the old server.

Then once copied over, I just switch the main IP on the 2 servers, then reboot them (at the same time), so they have the correct eth0 IP and are still online and you can access both servers still. Make sure to disable ipaliases (chkconfig ipaliases off) or remove the additional IP's on the source server too before rebooting. /etc/ips contains them usually, check for any ifcfg-eth0:($alias) files in /etc/sysconfig/network-scripts/ though to be sure.

/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network
/etc/hosts
/etc/resolv.conf
are the files needed to switch and make sure are correct before rebooting.

Code:
#!/bin/sh
# /////////////////////////////////////////
# //      SG 09/2004 CPanel              //
# //    CPanel transfer config script    //
# /////////////////////////////////////////
#
# HOST = User + IP / Hostname to copy files TO.
# All files copied from this server to the destinations server.
# Use this iscript to transfer THIS server to a new server.
HOST="[email protected]$1"
EMAIL="[email protected]"
if [ "$1" == "" ]; then
echo "Usage: $0 IP"
echo "Example: $0 123.123.123.123"
echo "Will remotely transfer all files from THIS server over to this server IP 123.123.123.123"
exit 1
fi
echo "	WARNING - YOU ARE GOING TO COPY FILES FROM THIS SERVER TO $1"
echo "  THIS WILL OVERWRITE THE FILES ON THE REMOTE HOST AT $1 !!"
echo ""
echo "	Is this correct? Enter y/n"
read confirm
if [ "$confirm" == "n" ]; then
echo "	User aborted. Type y to transfer files."
exit 1
elif [ "$confirm" == "N" ]; then
echo "  User aborted. Type y to transfer files."
exit 1
elif [ "$confirm" != "y" ]; then
echo "	Sorry I don't know what you neeed, enter y or n"
exit 1
else
# /etc User / IP's + passwd files
rsync -avz -e ssh /etc/passwd $HOST:/etc/
rsync -avz -e ssh /etc/shadow $HOST:/etc/
rsync -avz -e ssh /etc/group $HOST:/etc/
rsync -avz -e ssh /etc/wwwacct.conf $HOST:/etc/
rsync -avz -e ssh /etc/quota.conf $HOST:/etc/
rsync -avz -e ssh /etc/domainalias $HOST:/etc/
rsync -avz -e ssh /etc/remotedomains $HOST:/etc/
rsync -avz -e ssh /etc/reservedipreasons $HOST:/etc/
rsync -avz -e ssh /etc/reservedips $HOST:/etc/
rsync -avz -e ssh /etc/secondarymx $HOST:/etc/
rsync -avz -e ssh /etc/localdomains $HOST:/etc/
rsync -avz -e ssh /etc/userdomains $HOST:/etc/
rsync -avz -e ssh /etc/valiases $HOST:/etc/
rsync -avz -e ssh /etc/vfilters $HOST:/etc/
rsync -avz -e ssh /etc/vmail $HOST:/etc/
rsync -avz -e ssh /etc/tru* $HOST:/etc/
rsync -avz -e ssh /etc/ips $HOST:/etc/
rsync -avz -e ssh /etc/domainips $HOST:/etc/
rsync -avz -e ssh /etc/services $HOST:/etc/
# ftpd files
rsync -avz -e ssh /etc/sysconfig/pure-ftpd $HOST:/etc/sysconfig/
rsync -avz -e ssh /etc/pure-ftpd.conf $HOST:/etc/
rsync -avz -e ssh /etc/pure-ftpd $HOST:/etc/
rsync -avz -e ssh /etc/proftpd $HOST:/etc/
rsync -avz -e ssh /etc/proftpd.* $HOST:/etc/
# /var
rsync -avz -e ssh /var/cpanel $HOST:/var/
rsync -avz -e ssh /var/spool/cron $HOST:/var/spool/

# /usr config - 3rdparty
rsync -avz -e ssh /usr/share/ssl $HOST:/usr/share/
rsync -avz -e ssh /usr/local/cpanel $HOST:/usr/local/

# Apache
rsync -avz -e ssh /usr/local/apache/conf $HOST:/usr/local/apache/
rsync -avz -e ssh /usr/local/frontpage $HOST:/usr/local/

# Mysql config
rsync -avz -e ssh /root/.my.cnf $HOST:/root/
rsync -avz -e ssh /etc/my.cnf $HOST:/etc/

# Named
rsync -avz -e ssh /var/named $HOST:/var/
rsync -avz -e ssh /etc/named.conf $HOST:/etc/
rsync -avz -e ssh /etc/rndc.conf $HOST:/etc/

#User Files
# Mysql
rsync -avz -e ssh /var/lib/mysql $HOST:/var/lib/
#rsync -avz -e ssh $HOST:/var/lib/pgsql $DIR/var/lib/

for SITE in `ls /var/cpanel/users`
do
rsync -avz -e ssh /home/$SITE $HOST:/home/
done
date | mail -s "Restore completed for $HOST" $EMAIL
fi
exit 0
If you are doing the scenario above, have 2 machines online at once then transfer the files, this would be the best method (for me anyways)

You need to install cPanel, any custom apache modules, update php with your options etc on the new server first - then run the script on the source server, to copy the files from the source server to the destination server.

chmod +x script

./script 123.123.123.123 (your destination servers IP)

You may also want to setup ssh keys on the servers too - to save the password prompts while transferring files

on the source server

ssh-keygen -t dsa

Accept the defaults

Then

scp /root/.ssh/id_dsa.pub [email protected]:/root/.ssh/authorized_keys (make the directory /root/.ssh on 123.123.123.123 if it doesn't exist, and chmod it 700)

Then ssh into the box at 123.123.123.123 - no password.

A /scripts/upcp is probably recomended after the transfer of files and one more reboot won't hurt, to make sure all services are running correctly. ;)
 
Last edited:

SeanLee

Well-Known Member
May 23, 2004
52
1
156
Awesome!
Thank you very much for posting this. I will try this out over the weekend and then post my response here!

-Sean
 

SeanLee

Well-Known Member
May 23, 2004
52
1
156
Success!

This script worked GREAT. Everything went a lot smoother than I thought. It took about 2 hours total. Here's exactly what I did:

1) Install cPanel on new server (server2) - don't run the web config wizard yet.
2) Set cPanel IP on server2 and give server1 a different one.
3) Set up some ssh keys for server1 > server2 using ssh-keygen.
4) Run the script from server1.
5) Run the web config wizard on server2.
6) Update Kernel using up2date
7) Check /etc/localdomains /etc/hosts and /etc/resolv.conf for consistancy
8) Reboot

That's it!
Thanks so much for this script. I didn't have to change it at all.
This should be a sticky!!!

-Sean
:)
 

hyborian

Registered
Mar 10, 2004
4
0
151
Switching IP's

I'm interested in migrating servers in this method as well, however, I don't have the ability to swap ip's.. is this needed, or is there any way around this?
 

SeanLee

Well-Known Member
May 23, 2004
52
1
156
hyborian said:
I'm interested in migrating servers in this method as well, however, I don't have the ability to swap ip's.. is this needed, or is there any way around this?
When you set up cPanel, just set it up with whatever new IP you're going to use. I suppose you'll have to run through all the files you copied and replace the old IP with the new one.

-Sean
 

Biotron2000

Active Member
Jul 20, 2004
41
0
156
DigitalN said:
You may also want to setup ssh keys on the servers too - to save the password prompts while transferring files

on the source server

ssh-keygen -t dsa

Accept the defaults

Then

scp /root/.ssh/id_dsa.pub [email protected]:/root/.ssh/authorized_keys (make the directory /root/.ssh on 123.123.123.123 if it doesn't exist, and chmod it 700)

Then ssh into the box at 123.123.123.123 - no password.
If it doesn't connect, type:
/sbin/service sshd restart

on both servers. I almost pulled my hair out over that one.

I have a question, though.
I'm installing to a new server, from Fedora Core 2 to CentOS 4.1. I ran the script, and everything copied over, but the IP addresses did not come up. During boot, it said it was bringing them up, but they were inaccessible. Did I miss something?
 
Last edited:

CoolMike

Well-Known Member
Sep 6, 2001
313
0
316
Is this script transfering also the reseller account settings?

Or is any other thing missing?

Michael
 

Stefaans

Well-Known Member
Mar 5, 2002
461
4
318
Vancouver, Canada
Wow Michael, you managed to dig up quite an old thread here :eek:

Is this script transfering also the reseller account settings?
Since the reseller settings are saved in /var/cpanel, I think the script will do it for you. The relevant line that will do it for you is this one:
Code:
rsync -avz -e ssh /var/cpanel $HOST:/var/
 

jpeacock

Member
May 17, 2006
12
0
151
used this script last night to move all the accounts from an old box to a new one. worked absolutely wonderfully :) Thanks!

One thing that might not be related though, I'm using the same iptables rules from before, but I'm not able to ftp into the box in either passive or active mode. any ideas? Any time I stop iptables, it works great, so I'm guessing it'd be just a rules issue. ideas on what happened?
 

jpeacock

Member
May 17, 2006
12
0
151
whoops. guess I didn't put ip_conntrack_ftp into iptables-config. my mistake. thanks for the great script :)