From time to time every IT professional will need to migrate a site from one server to another. This could be due to higher resources requirements or bad experiences with the current provider.

Before we do the migration we need to do proper server migration planning especially if we are going to cancel the old server soon after the migration. When the old VPS is destroyed you won't be able to recover anything* ( * some hosting providers allow you to keep some snapshots, however, you have to double check that).

How to go proceed with the migration

It would be far more effective to make the two servers *talk* to each other rather than downloading the site on your local machine and then reuploading it to the new server because servers have better connectivity. This is especially true if the size of the site is more than 250MB.

LFTP (http://lftp.yar.ru/) is a sophisticated ftp/http client, and a file transfer program supporting a number of network protocols. It has bookmarks, a built-in mirror command, and can transfer several files in parallel. It was designed with reliability in mind. LFTP is free software, distributed under the GNU GPL license.

If you don't have it installed ubuntu users can do this

sudo apt-get install lftp

 

Since the migration process can take some time it is highly recommended to install a linux program called screen. Using screen program if you get disconnected that won't stop the transfer. You can connect to that process later.
The following steps have to be done on the new server.

 

On ubuntu you can do this

sudo apt-get install screen

On fedora

yum install screen

 

When it's installed you can run it as follows

screen

 

Next we're going to run the command

lftp --password='YOUR_PASSWORD' sftp://YOUR_USERNAME@old-server.com -e 'set ssl:verify-certificate no; set sftp:auto-confirm yes; mirror -v --continue / /var/www/vhosts /example.com'

 

LFTP will start from root of the remote path that's / and will store the files locally in /var/www/vhosts/example.com

 

To disconnect from the screen process (and leave it running) press CTRL+A and then d (to detach). You are supposed to do this when you're seeing the transfer running.
To reconnect to the process later do

screen -r

 

Here are some useful 'screen' commands.

10 Screen Command Examples to Manage Linux Terminals

 

LFTP Errors: "Fatal error: Host key verification failed"

 

Related

Referral Note: When you purchase through an referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer