Linux – Cloning a Linux server to another server

linux

Let's say I have two web servers (in a datacenter), A and B. I don't have physical access to any of the servers, only root ssh access.

A is an old server with old hardware, but it's configured the way I want it (security, settings, etc..), while B is a new server with newer hardware (totally different from A), and it has a fresh install of CentOS (for example).

What's the best way to clone server A to server B, so all my files,settings,applications are moved from A to B?

Best Answer

If the newer server runs the same OS version, you could run a simple script from the newer server that copies most of the files:

#!/bin/bash

# Source
SSHSERVER="root@source.server"
SSHPORT="22"

EXCLUDE="/boot/
/lib/modules/
/etc/modules/
/etc/lilo.conf
/etc/fstab
/etc/hostname
/etc/hosts
/etc/mtab
/etc/shadow
/etc/shadow-
/etc/ssh/
/proc/
/dev/
lost+found/
/etc/network/interfaces
/root/
/sys/
/run/
temp/
tmp/
log/"

printf '%s\n' $EXCLUDE > exclude.txt
rsync -avz --exclude-from=exclude.txt -e "ssh -p $SSHPORT" $SSHSERVER:/ /

I used this script in the past to duplicate Debian servers, and it worked fine but some manual (re)configuration, like apt-get install -f was sometimes required. Therefore, use with caution, perferrably in a test environment first.

Related Topic