Linux – Clone a working Linux server

clonelinux

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?

Best Answer

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.