22

Does anybody know of a way to clone a live linux system? I have a live installation running a production site. Problem is, I'm needing to clone it (without bring it down), and then move it over (restore) to a virtual machine. I'm basically migrating from physical hardware to virtual hardware.

mattdm
  • 6,550
  • 1
  • 25
  • 48
drewrockshard
  • 1,753
  • 4
  • 20
  • 27

7 Answers7

13

On the source machine:

dump -0 -f - / | ssh -c blowfish root@target_machine "cd /; restore -rf -"

This will dump the fs on your source machine, copy it over ssh and on the target machine it will restore it.

Of course you need to repeat this for every fs.

'blowfish' is there just to make it for faster compression and decompression.

mrkafk
  • 379
  • 1
  • 2
  • 7
  • This one seemed to work the most efficient. – drewrockshard Jan 25 '11 at 16:35
  • i can not get it to like the lower case r. i had part of this working by separating `-rf to -r -f`, but now **restore: invalid option -- 'r'** **cat: invalid option -- 'r'** – rjt Mar 13 '15 at 18:22
  • 6
    Is this answer still valid? What would happen if you were to have a running MySQL service on the box? – MirroredFate Jun 26 '15 at 21:13
7

VMWare Converter can do most modern OS's without shutting the server down, but as Dennis pointed out, we really need to know which OS you're running.

You'll end up with a virtual image of your server when you're done, rather than a raw disk image, but it's usually good enough for most work, depending on what you want to do with it once you've done it.

Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
  • It's running on Fedora. FYI, I'm planning to image it for virtualization later, probably in Xen. – Str Mar 08 '11 at 11:30
  • For virtualization purpose, if I'm not mistaken the image have to be in virtual image rather than raw disk image, right? – Str Mar 08 '11 at 11:31
  • 1
    @Str, if you know what the OS is please edit your question to say so and use appropriate tags. – John Gardeniers Mar 08 '11 at 11:44
  • @Str - that's correct, however you didn't mention if you were going to be virtualising the machine or not, just that you wanted to clone it. – Mark Henderson Mar 08 '11 at 20:32
2

We generally do this:

  • Boot the target virtual host off a cd (or netboot it)
  • Prepare the filesystems on the virtual host (that is, prepare the disk(s), create the fileystems, and mount them).
  • Rsync the files from the physical host to the virtual host
  • Install the boot loader on the target host

This works great, as long as the data you're copying over is relatively stateless. If you're dealing, for example, with a database server, particularly one with a lot of activity, you will need to make sure that database is quiescent before you make the final cutover...so, something like this, after everything else is ready:

  • Stop the database
  • Perform a final rsync of the data
  • Shut down the physical host
  • Start up the virtual host
larsks
  • 41,276
  • 13
  • 117
  • 170
1

Which VM platform are you migrating to? VMWare has a converter for Linux. It'll convert a powered on machine.

Jason Berg
  • 18,954
  • 6
  • 38
  • 55
  • In the end, it's in house, and VMWare based. The control panel is custom, so we'd basically be loading a live CD, and expanding/extracting/etc onto the VM. I'm not sure I can get access to the VM infrastructure to do the VMWare converter, but that all depends what is involved with this. To test however, I was going to try to migrate it over to a virtualbox vm just to see if this proof of concept worked at all. – drewrockshard Jan 21 '11 at 17:52
  • Do you think I could run the convertor on the physical machine and then "import" the converted vm into vmware (never used the convertor, so my terminology might be off). – drewrockshard Jan 21 '11 at 17:53
  • The converter doesn't really work that way. Check out this link. It should show you the basics of how a conversion works http://www.vladan.fr/how-to-p2v-linux-into-vmware-esx-server/ – Jason Berg Jan 21 '11 at 18:21
  • Is there a way to bypass the vmware infrastucture import so that I can keep the "converted" image locally on my system, or do I have to migrate to another infrastructure (no local ability)? – drewrockshard Jan 21 '11 at 18:59
  • Note that the VMWare Converter (currently) requires Windows, though it can migrate a Linux physical computer to a virtual machine. – Greg Glockner Jun 22 '16 at 19:42
1

Have a look at VMWare converter which I believe allows live system cloning.

user9517
  • 114,104
  • 20
  • 206
  • 289
0

Look at VMware Converter (it's free if you have vCenter) or Plate Spin (one of their products is a converter).

Plate Spin will do a machine live, with minimal downtime to cut over.

With VMware converter, it'll do a live machine (if there's a database it might be out of sync) just don't have it boot the VM when it is finished. Then disconnect the vNIC and then boot the machine, log in via the console and change the IPs, etc. Then reconnect the vNIC.

mrdenny
  • 27,074
  • 4
  • 40
  • 68
0

Its impossible to get a consistent snapshot without stopping all operations which may change the state of the system.

Unless the application has been explicitly designed to accomodate this kind of operation (i.e. all processing handled via queueable messages) it is be impossible to get a consistent snapshot without bringing the system down (or at least disabling the transactional component).

However it is possible to reduce the time window for snap-shotting the system significantly (e.g. by removing a mirror from a RAID set then remounting it elsewhere). And the shorter the time it takes to generate the snapshot, the less likely that transactions will span the operation.

And most filesystems / DBS will support some sort of journalling which should allow most broken operations to be either recovered or rolled back.

symcbean
  • 19,931
  • 1
  • 29
  • 49