2

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?

2
  • 3
    Don't. Chances are high that the newer versions of the programs don't work with the old config. Maybe not all, but some. Configure the new server manually. Aug 7, 2018 at 9:24
  • 3
    "Cloning" implies a bit-for-bit copy of all data and settings, which is usually at odds with 'migrating" both your data and configuration settings to a new major OS version and newer versions of your application layer.
    – HBruijn
    Aug 7, 2018 at 9:26

2 Answers 2

6

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="[email protected]"
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, preferably in a test environment first.

3

Migrate, do not clone. Different versions, different hardware, evolving best practices will require slightly different configuration.

Spend some effort to create documentation and automation to configure a fresh OS install from scratch. This might be a well-commented script or playbook. Use this to deploy.

If near-identical hardware or VM, that could be a clone. Copy the entire OS disk and re-IP it. You inherit all the quirks of the old install, but it is the same.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .