I have two Debian 9 servers, server A and Server B.

Server A is a LAMP stack server.

Server A is slow. Server B is fast.

I want to clone server A to server B without shutting down server A.

How do I do that?

I think I can do something like this:

  1. Install Debian 9 on server B as a base installation
  2. use rsync to copy over all of /home/ from A to B, then copy over /etc/passwd, /etc/groups, and /etc/shadow
  3. Dump the packages that are installed on A, create a script to install those on B.
  4. Dump the MySQL databases from A, copy to B, and import
  5. Copy over the contents of /etc/ with rsync.

Or... could I just rsync the ENTIRE server from B to A?


Please read over each link carefully before attempting any commands.

I have used this rsync example by user ericslaw to successfully clone my working Linux install to a different drive.

You can mount a remote or local target file system to /mnt of your source file system. As root(sudo) run the following:

mount /dev/sdb1 /mnt

/dev/sdb1 is your second server disk. It can be remote or local, whatever works best for you.

rsync -gloptruncv \
      --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found} \ 
      / /mnt 

This will be a dry run. If there are no errors then you should be good to go to exclude the n option. After which you need to follow the advice in this post. After your back up has completed ( You can even use their options instead depending on your circumstances) Then reset /mnt/etc/fstab for the boot and swap partitions. I highly recommend these entries are based on the UUID of the block devices. blkid will tell the information you need. After fstab is fixed you need to run grub-install /dev/[serverB disk] to be able to boot. Alternatively you can chroot into the backup and install grub that way.

 chroot /mnt
 grub-install --recheck /dev/sdb1

Lastly you may need to recreate the missing folders of your backup (/dev/, /proc/, /sys/, /tmp/, /run/, /mnt/, /media/, and /lost+found).

This can also be done in reverse. Have Server B mount Server A's disk and then sync non system files between the two. This is easiest if Server A and B are running the same version of the same distro.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.