CentOS – How to Make an Identical Copy

centosreplication

I have a CENTOS server running and i want to make identical copy of it(all software,users), like twin server for mirroring purposes. how do i do that?

Best Answer

While dd will copy one mounted drive to another, the copy will be inconsistent. The filesystem is constantly changing, and if you are using a journaled filesystem, even more so. Using dd works best when the drive is static, i.e. read-only. Most of the time, this isn't an option, but if you do have it read-only, this will work fine.

There are other tools to perform this cloning function. But the easiest is to simply use LVM's mirror functionality. The caveat is that you will need to have the existing filesystem on LVM already. Using an LVM mirror, you can make hot copies of the filesystem, and when you break the mirror to obtain your second drive, the filesystem image will be in a consistent state, because all the recorded changes will be sent consistently. It requires little work other than starting the mirror process and stopping it once the original has replicated completely.

If for some reason you don't want to use the mirror function, you can always create a snapshot of the filesystem and replicate the read-only snapshot to another drive. While this is not as automatic as mirroring, and it is a bit messy (extra steps), it can be made to work just fine.

Last, you can always try to rsync your way into this. This sounds like a strange way to do it, but I've used this to successfully replicate a server 400 miles away to a local drive. The catch was that I had to make a manual change to the /etc/fstab file (the paritions were different) but otherwise it boots fine.

That leaves a single sore point: making the drive bootable. Using dd will copy the boot loader over (as it is a block-by-block copy) but if you use the LVM or rsync methods, you'll need to re-install the bootloader. Fortunately, this isn't too hard and can be easily done to drives other than the current (original?) root filesystmem.