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?
4 Answers
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.
- 1,169
- 1
- 8
- 20
-
1+1 for the linuxfocus reference – Bozojoe Dec 27 '12 at 04: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.
- 1,342
- 8
- 14
-
5This 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 ( http://en.wikipedia.org/wiki/Runlevel#Typical_Linux_runlevels ), do the snapshot, and restart in a higher runlevel. – Lee B Nov 01 '09 at 00:23
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
- 745
- 1
- 6
- 15
-
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 02 '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.
- 1,209
- 1
- 8
- 17