How can I migrate a VPS from one provider to another while keeping configurations? Can I just use `rsync / destination:/`?

How can I migrate from one VPS to another, while keeping the configurations?

I saw this question Best way to migrate data between two linux VPS

But that was only to migrate the data.

I have set up an email server (Dovecot/Postfix) which is a pain to set up, Tomcat, PHP, Apache, Webmin, etc. and would like to copy the configurations for them without having to set everything up again.

I'm afraid if I copy the root directories, there will be special files like /dev that should not be copied.


Solution 1:

I went through that exact task a few days ago. The steps I performed was essentially this:

  1. Create a bind mount of the root file system in a separate location on the source VPS. For example mount --bind / /mnt/servername
  2. Create a tar file containing all of /mnt/servername. For example tar -C /mnt -c servername | ssh user@newserver dd of=copy.tar
  3. Extract the tar file. At this point it is important to use the --numeric-owner flag for tar.
  4. Replace the network configuration in the extracted image with one suitable for the destination VPS.
  5. Move the files into their final position (this is the tricky part).

Step 5 becomes a lot simpler if the destination VPS offers management features such as netboot, virtual console, etc. The VPS I was migrating to offered both of the above. The virtual console was utilizing a VNC client connecting to the hypervisor for access to the virtual display.

If you don't have such management features, you need to get that step right in the first try. And updating the boot loader is challenging.