Hotcloning: cloning a running server

by Olivier Sessink

There are various ways to clone a machine. Make an image, and restore the image on other hardware. However, if you want to move your server to new hardware, with very little downtime (within some minutes), you can use the description is this article. The article assumes a Debian Linux system, but this will work with most open source operating systems.

Install a base system

You will need a couple of things before you can start hotcloning:

Synchronize the data

Using rsync we can synchronize old_machine to new_machine. Rsync only transfers differences, so you can stop and restart rsync any time, and you can also resync several days later without starting all over again, or rerun rsync to transfer all changed files.

Exclude patterns for rsync

Some files should not be transferred because they are hardware specific, or are available by default, or auto-generated.

These are specific for your hardware and your partition setup:

/boot/
/lib/modules
/etc/modules
/etc/lilo.conf
/etc/fstab
/etc/mtab

These are already available. /proc is a virtual filesystem provided by the running kernel, /dev is the device tree from the base install, lost+found are directories created during partition formatting:

/proc
/dev
lost+found/

These are excluded because you want to keep the logs separate for each machine, and you want (for now) to have a different network setup for each machine:

/var/log
/etc/network/interfaces

An exclude file contains all these entries, every entry on a new line. Click here for an exclude file. Warning: if you have network mounts you need to exclude them too!!!

Sync data

rsync -e ssh -avz --exclude-from=/root/hotclone_exclude old_server:/ /

Switch servers!

You're up and running!!!!!!!!!