# Using rsync to migrate or clone linux system
P2V,V2V
NOTE: Before hot cloning, ensure you disable all the services that involve shipping or writing data e.g. databases, mail service, etc.
# Install Rsync in Linux
~]# yum install -y rsync | |
~]# rsync --version | |
rsync version 3.1.2 protocol version 31 | |
Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others. | |
Web site: http://rsync.samba.org/ | |
Capabilities: | |
64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, | |
socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, | |
append, ACLs, xattrs, iconv, symtimes, prealloc | |
rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you | |
are welcome to redistribute it under certain conditions. See the GNU | |
General Public Licence for details. |
# Cloning a Linux Server
~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa | |
~]# ssh-copy-id 192.168.3.115 | |
~]# cat >/tmp/exclude-files.txt <<EOF | |
/root/.ssh | |
/boot | |
/dev | |
/tmp | |
/sys | |
/proc | |
/mnt | |
/etc/fstab | |
/etc/mtab | |
/etc/mdadm.conf | |
/etc/sysconfig/network* | |
EOF | |
~]# cat >/tmp/rsync.sh <<EOF | |
#!/bin/bash | |
rsync -avP -e 'ssh -o StrictHostKeyChecking=no' --exclude-from=/tmp/exclude-files.txt / 192.168.3.115:/ | |
EOF | |
~]# chmod +x /tmp/rsync.sh | |
~]# nohup /tmp/rsync.sh & |
If have an increment rsync, remove the /root/.ssh/known_hosts file on the source and copy ssh key to the destination again.