Hot Clone is the term used to describe to completely clone a Linux server using r-sync across the network. This is useful in situations which you would like to create a clone with little to no downtime that would be typical of taking the original server offline. You can use this to perhaps move a single server in to a cluster environment or certain situation in which you want to upgrade or reduce drives etc.
This guide makes a couple assumptions:
First both servers need to have the same disk configuration. Either both servers use hardware raid, software raid, or single disks. They typically need to match.
The new server should have the same major install release as the source server. Â So both servers would be CentOS 6.x or both need to be 7.x.
The new server has hard drive partitions in a the same format as the old server and they are either the same size or can accommodate all of the used space on the source system.
Services which are writing data should be stopped at the time of the sync (ie mail, databases etc).
Prepare the systems:
Install needed software packages on both servers:
yum install -y rsync
On the server you want to copy from perform the following:
Create and edit /root/exclude-files.txt and add the following:
/boot /dev /tmp /sys /proc /backup /etc/fstab /etc/mtab /etc/mdadm.conf /etc/sysconfig/network*
This excludes files which directly pertain to the source system and should not be copied to the new system.
Hot Clone the server:
Once you have saved that file you can go ahead and rsync to the server you want to copy to:
rsync -vPa -e 'ssh -o StrictHostKeyChecking=no' --exclude-from=/root/exclude-files.txt / DESTINATIONIP:/
This will rsync over everything from the source system to the new system. The size of the drives and load on the servers will determine how long the copy will take. Â Be sure to update DESTINATIONIP with the IP address or hostname of the server you are copying to.
After the rsync has completed you can reboot the freshly copied system to have it load everything that has been copied. If you were going to replace the old system with the new system and wanted the same IP addresses, host name etc to be used, Â you would then remove /etc/sysconfig/network* from the exclusion file.
Once the new server is back up from the reboot. Go ahead and login using the old servers login credentials and verify everything is working as expected.
Your target machine is not going to boot without a boot loader or initial ramdisk. This is ridiculous.
Hello Chris,
The assumption is that you have already done a base install with a boot loader/ ram disk, this was specified in the assumptions portion of the guide…
Worked great! I needed a Sangoma distribution (CentOs 7) on a VPS but no provider here has it nor did they allow me to send them an ISO. I then just installad a bare Sangoma on Vmware, A Bare CentOS 7 at the VPS provider follow your WONDERFULL instructions and presto! My Sangoma is now on a VPS 🙂 Thank you very very much!
Awesome, so glad we could help!!
Hello Anthony and linuxadmin, I wanna move my old OS centos 7 on VPS A(provided by bandwagonhost) to VPS B (running a basic install of Centos 7 provided by google cloud platform ) , I have followed the instructions listed above, After the rsync has completed, I reboot the VPS B,but the freshly copied system didn’t boot , the new server wasn’t back up from the reboot. I can’t login using the old servers login credentials. I have started it over many times, and tried to generate new grub cfg with grub-install and grub-mkconfig . but I still failed to… Read more »
Hello,
Could you provide details on the boot error?
This won’t work on large live databases. You need to shut down stuff that locks and writes to files during the rsync-transfer.
Hello Rene,
You are correct, I have added note that services which write data should be stopped prior to the execution.
Worked brilliantly!
Thanks a ton for this.
Glad to hear it worked out for you.
Can I initiate the rsync from the destination server running a basic install of Centos 7? What do I have to change on the commandline
Hello,
Its possible this could work(untested), is there a reason why you want to initiate it on the destination vs the origin server? That said, to reverse the rsync it would be
rsync -vPa -e 'ssh -o StrictHostKeyChecking=no' --exclude-from=/root/exclude-files.txt DESTINATIONIP:/ /
Would this work for Debian 9 with some small adjustment to the /root/exclude-files.txt at all?
If someone wants to post an example I would appreciate it.
Thanks
Hello,
Yes this would likely work with some minor differences to the exclusions.