How to Clone a CentOS Server with Rsync

Cloning is the practice of cloning an exact copy of an existing Live Linux server using the rsync command-line tool. Cloning requires 2 instances of servers – the server to be cloned and the destination server where the cloning process will occur. The rsync command-line tool synchronizes all the files and directories from the server being cloned to the destination server.

In this guide, you will learn how to hot clone a CentOS server with Rsync file synchronization tool.

Lab Setup

Here’s the lab setup that we are using for this guide.

  • Source Server – CentOS 7 – 192.168.2.103
  • Destination Server – CentOS 7 – 192.168.2.110

The source server is the one we are going to clone onto the destination server.

Setup and Requirements

Before proceeding, ensure that you have met the prerequisites below:

  • Both servers need to be running the same release of the operating system i.e CentOS 7.x, CentOS 8.x, etc.
  • Additionally, the servers should have identical file systems and the same hard disk configuration i.e whether single-disks or in RAID configuration.
NOTE: Before hot cloning, ensure you disable all the services that involve shipping or writing data e.g databases, mail service, etc.

Step 1: Installing the Rsync Tool in CentOS

For cloning to be successful the rsync command-line tool needs to be present on both servers. This will be used for mirroring the source server to the destination server and syncing all the differences between the two systems. Thankfully, modern systems come with rsync already pre-installed.

To check the version of rsync installed run:

$ rsync --version

If you want to view additional information about rsync, execute the following rpm command:

$ rpm -qi rsync
Check Rsync Version in CentOS
Check Rsync Version in CentOS

If rsync is missing, run the following command to install it in RHEL / CentOS / Fedora systems.

$ sudo yum install rsync

Step 2: Configure the Source Server

There are directories and files that you may want to exclude from cloning because they are either already available in the destination server or are autogenerated. These include the /boot, /tmp and /dev directories.

Therefore, create an exclusion file /root/exclude-files.txt and add the following entries:

/boot
/dev
/tmp
/sys
/proc
/backup
/etc/fstab
/etc/mtab
/etc/mdadm.conf
/etc/sysconfig/network*

Save and exit the configuration file.

Step 3: Clone the CentOS Server

With everything set, proceed and rsync your server to the remote or destination server using the command:

$ sudo rsync -vPa -e 'ssh -o StrictHostKeyChecking=no' --exclude-from=/root/exclude-files.txt / REMOTE-IP:/
Clone CentOS Server
Clone CentOS Server

The command will rsync everything from the source server to the destination server while excluding the files and directories you defined earlier on. Be sure to replace the REMOTE-IP: option with your destination server’s IP address.

After the synching is done, reboot the destination system to reload the changes and thereafter, boot into the server using the source server’s credentials. Feel free to decommission the old server since you now have a mirror copy of it.

If you read this far, tweet to the author to show them you care. Tweet a thanks
James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 thoughts on “How to Clone a CentOS Server with Rsync”

  1. Just wanted to share that I could successfully clone a server to another, thank you! I found it’s much faster and has a lot fewer conflicts to boot to a live ISO, attach block storage to the source server, `dd` an image, and then rsync the relevant parts to the destination server.

    Reply
  2. Thank you for your article.

    But I am not sure we can use “clone” expression in your example. It seems to me, in that case, we can use rsync as a copy-paste tool only, not a cloning one. Here we can see only some folders are copied from one server to another one.

    In my opinion, the most robust cloning tool in Linux is dd command. In that case, there is no requirement to have a pre-installed OS on a destination server before running dd command.

    “Additionally, the servers should have identical file systems and the same hard disk configuration i.e whether single-disks or in RAID configuration.” – what will happen if the size of HDD is larger on a destination server?

    Thank you!

    Reply

Leave a Reply to Chiron Se Cancel reply

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.