Clone a working Linux server

I need to clone a working linux server. We cannot shut down the working server. Is there any way I can get a clone and deploy it on another server?


There are many ways to copy disks, file systems or files. Generally, copying the file system gives you a good clone with the flexibility that it can be a slightly different size on the target system. With the target system running some sort of live Linux (knoppix, ubuntu live, etc.), booted from a cdrom, you can create the partitions on the disk using fdisk or your favorite partition application. Assuming you have an SSH server running on the source system, take an approach similar to this:

http://www.linuxfocus.org/English/March2005/article370.shtml

The magic is happening in this command:

ssh sourcePC 'dump -0 -f - /' | restore -r -f -

When using any particular method to clone disks on a live Linux environment, your only concern would likely be with the databases. The best way to backup and restore a database is to use their dump tool to make an ascii file snapshot of the database just prior to the file system dump. For mysql there is :

mysqldump --all-databases > mysql_databases.sql

For postgresql, there is:

pg_dumpall > pg_databases.sql

If you encounter any sort of consistancy error on the new system, restore the database. Alternately, once you have shut off services on the source system, do the DB dump again, and restore on the target, and you will not miss any recently modified data.


Construct a disk layout on the new machine as you want it.

Use rsync to transfer the contents of the disk over. Repeat a few times to catch up completely.

On the new machine experiment with what you will need to do additionally to boot properly. Grub for instance, and get it to be in a consistent state.

Until you can shut the old machine down, rsync on regular intervals to keep the new disk close to the old one.

Then bring the old one to maintainance mode, rsync once more, and boot the new one which should come up behaving like the old one.


My coworker swears by System Imager:

http://wiki.systemimager.org/index.php/Main_Page

I don't know how well it would work for "live" systems.

Otherwise I think you are stuck doing things manually:

  • Verify there isn't any install applications outside of the repositories
  • Dump the list of installed packages and install them on the new server
  • Copy over config files
  • Restore databases