A few days ago I wanted to Migrate an Ubuntu VPS from one provider to another. I tried to take a snapshot and try to migrate, but it did not work. The VPS had few random services, so migrating services one by one was not easy. What I did was set up a new Ubuntu VPS with the same OS version, rsync files from source VPS to new VPS.
Make sure you take a backup of your server before doing it. In case anything goes wrong, you should be able to restore from back or OS reload.
Install rsync on source and destination servers.
apt install rsync
yum install rsync
On the source server, create a file
add following content
These files won’t be copied to the new VPS. If you don’t have any other folders or files, that you don’t want to be copied to the new server, you can add to the list.
Now run rsync on the source server to copy over files to the new server
rsync -avzP --exclude-from=/root/no_copy / root@NEW_SERVER_IP:/
In the command above, replace NEW_SERVER_IP with the new server IP address.
When we do rsync, all files get copied to the new server. After the first rsync run, you can run rsync command any number of times, only changed files copied and will finish must faster as less data need to be copied to the new server.
After the first rsync is completed, we will stop all services on the source and destination server like MySQL, Apache, Nginx, etc… so no data get changed while we doing the rsync. Now do another rsync, reboot the destination server, see if everything works fine.