CentOS7 – Migration Linux with Rsync

Prepare the systems:

Linux Base Package

echo "PS1='\033[1;33m\t \033[1;33m[\u@\H] \033[1;35m\w\033[0;0m\n#'" >> /root/.bashrc

. .bashrc

rm -f anaconda-ks.cfg

yum -y install epel-release

# For Physical Server
yum -y install rsync htop dmidecode wget screen net-tools snmpd net-snmp-utils perl perl-libwww-perl vim sysstat iftop zip unzip iptstate yum-utils nc lsof net-snmp ntp bash-completion curl lsof bridge-utils bind-utils nfs-utils telnet bzip2 pciutils git perl-core

systemctl stop NetworkManager 
systemctl disable NetworkManager
yum -y erase NetworkManager
systemctl stop postfix
yum -y remove postfix
systemctl stop chronyd
yum -y remove chrony
yum -y remove firewalld* 

# sshd config
sed -i '/Defaults    requiretty/c #Defaults    requiretty' /etc/sudoers
sed -i '/#UseDNS yes/c UseDNS no' /etc/ssh/sshd_config
systemctl restart sshd

# set NTP
sed -i '/server 0.centos.pool.ntp.org iburst/c server 202.170.119.19' /etc/ntp.conf
sed -i '/server 1.centos.pool.ntp.org iburst/c server 202.170.119.9' /etc/ntp.conf
sed -i '/server 2.centos.pool.ntp.org iburst/c server 103.246.188.99' /etc/ntp.conf
sed -i '/server 3.centos.pool.ntp.org iburst/c #' /etc/ntp.conf
systemctl enable ntpd
systemctl restart ntpd

# set SELINUX=permissive
setenforce 0
sed -i '/SELINUX=enforcing/c SELINUX=disabled' /etc/sysconfig/selinux 
sed -i '/SELINUX=enforcing/c SELINUX=disabled' /etc/selinux/config

echo "export EDITOR=\"vim\"" >> .bashrc
echo "alias vi='vim'"  >> .bashrc

# Restart to Lastest
reboot

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:

Create and edit /root/exclude-files.txt and add the following:

cat > /root/exclude-files.txt
/boot
/dev
/tmp
/sys
/proc
/backup
/etc/fstab
/etc/mtab
/etc/mdadm.conf
/etc/sysconfig/network*

# Ctrl-D

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 -p 22' --exclude-from=/root/exclude-files.txt / DESTINATIONIP:/
#OR
rsync -vPa -e 'ssh -p 22' --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.