Cloning is the meticulous course of of making an actual reproduction of a stay Linux server by using the highly effective rsync command-line software, which is an environment friendly file synchronization and switch software.
Cloning entails the utilization of two server cases: the supply server, which serves because the server to be cloned, and the vacation spot server, the place the precise cloning course of takes place.
By way of the employment of the rsync command, an intricate synchronization of all recordsdata and directories from the supply server to the vacation spot server is completed.
On this information, you’ll learn to sizzling clone a Linux server with the Rsync file synchronization software.
Lab Setup
Right here’s the lab setup that we’re utilizing for this information, you may clone any Linux distribution utilizing the rsync command.
- Supply Server – RHEL 9 – 192.168.2.103
- Vacation spot Server – RHEL 9 – 192.168.2.110
The supply server is the one we’re going to clone onto the vacation spot server.
Setup and Necessities
Earlier than continuing, guarantee that you’ve met the stipulations under:
- Each servers should be working the identical launch of the working system i.e. RHEL 9.x or RHEL 8.x, and so forth.
- Moreover, the servers ought to have an identical file programs and the identical laborious disk configuration i.e. whether or not single-disks or in RAID configuration.
NOTE: Earlier than sizzling cloning, make sure you disable all of the companies that contain delivery or writing knowledge e.g. databases, mail service, and so forth.
Set up Rsync in Linux
For cloning to achieve success the rsync command-line software must be current on each servers, which might be used for mirroring the supply server to the vacation spot server and syncing all of the variations between the 2 programs.
Fortunately, fashionable Linux programs include rsync already pre-installed and you’ll examine the model of rsync put in by working:
$ rsync --version
If you wish to view further details about rsync, execute the next rpm command or dpkg-query command:
$ rpm -qi rsync [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ dpkg-query --status rsync [On Debian, Ubuntu and Mint]

If rsync is lacking, use the default package deal supervisor to put in it in your system.
$ sudo apt set up rsync [On Debian, Ubuntu and Mint] $ sudo yum set up rsync [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/rsync [On Gentoo Linux] $ sudo apk add rsync [On Alpine Linux] $ sudo pacman -S rsync [On Arch Linux] $ sudo zypper set up rsync [On OpenSUSE]
Configure Supply Linux Server
There are directories and recordsdata that you could be need to exclude from cloning as a result of they’re both already out there within the vacation spot server or are autogenerated. These embrace the /boot
, /tmp
and /dev
directories.
Subsequently, create an exclusion file /root/exclude-files.txt
and add the next entries:
/boot /dev /tmp /sys /proc /backup /and so forth/fstab /and so forth/mtab /and so forth/mdadm.conf /and so forth/sysconfig/community*
Save and exit the configuration file.
Cloning a Linux Server
With every part set, proceed and rsync your server to the distant or vacation spot server utilizing the command:
$ sudo rsync -vPa -e 'ssh -o StrictHostKeyChecking=no' --exclude-from=/root/exclude-files.txt / REMOTE-IP:/

The command will rsync every part from the supply server to the vacation spot server whereas excluding the recordsdata and directories you outlined earlier on. Be sure you change the REMOTE-IP:
possibility along with your vacation spot server’s IP handle.
Let’s break down the command and its elements:
sudo
– It’s a command that enables the execution of a command with administrative privileges.rsync
– The rsync command itself, is used for file synchronization and switch.-v
: This feature permits verbose output, offering detailed details about the progress of the synchronization.-P
– This feature is equal to--progress
and permits partial file transfers and shows the progress of every file in the course of the synchronization.-a
– This feature stands for “archive mode” and is a shorthand for preserving essential file attributes comparable to permissions, possession, timestamps, and so forth.-e
– This feature specifies the distant shell to make use of for the synchronization.-o StrictHostKeyChecking=no
– Disables strict host key checking, which signifies that the SSH connection won’t immediate for affirmation if the distant server’s host key’s unknown.--exclude-from=/root/exclude-files.txt
– This feature permits you to specify a file that accommodates a listing of patterns or paths to be excluded from the synchronization./
– The ahead slash represents the supply listing or root listing that might be cloned.REMOTE-IP:/
– Specifies the vacation spot server’s IP handle or hostname adopted by a colon and ahead slash. It signifies the distant listing the place the cloned recordsdata might be copied.
After the synching is finished, reboot the vacation spot system to reload the modifications and thereafter, boot into the server utilizing the supply server’s credentials. Be at liberty to decommission the outdated server because you now have a mirror copy of it.