Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Oct 31 '09 at 22:23

This question came from our site for professional and enthusiast programmers.

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:

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.

share|improve this answer
+1 for the linuxfocus reference – Bozojoe Dec 27 '12 at 4:41

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.

share|improve this answer
This could cause data corruption. To guarantee a proper copy, of files (including live databases), you would need to be able to run the entire rsync command in one atomic operation, while the system was paused. An LVM snapshot would be atomic, or building a RAID mirror and then disconnecting one of the drives and putting it in the new machine. Even then though, you'd really need to go to runlevel 1 ( ), do the snapshot, and restart in a higher runlevel. – Lee B Nov 1 '09 at 0:23

My coworker swears by System Imager:

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
share|improve this answer
systemimager rocks. It does work on a live system, with the same provisos for running rsync to copy a live system's state. Some apps will need to be shutdown or dumped to disk (eg mysql DBs) before copying and will need to be restored on the new system. – gbjbaanb Nov 2 '09 at 13:12

Provided you can get your databases into a consistent state on disk, you could simply use DAR to make a copy of everything, then write it back out to your new server.

Syncing your databases to a consistent state on disk may be tricky, but just taking a snapshot and then restoring from that after you restore the DAR image may work. DAR will impact server performance while it's running.

Once you've got your image though, you can tweak the network settings and should be able to bring it back up no problem.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.