Migrate Old Server to New

Table of Contents

Situation

Two virtual servers with command line ssh and sftp access, administered from my local machine. I want to migrate everything from one server to the other, without an additional stop on the local machine. The web site in question is located in a www subfolder of the home folder (sometimes also public_html or similar).

Please check if the server software is compatible; in my case, both servers use Apache 2.4.x and PHP 7.4.x, so Everything Should Work (tm) and I can re-use .htaccess and .htpasswd files.

Copying

ssh into the new server.

[new_server] $> mkdir transfer; cd transfer
[new_server] $> sftp -r user@old_server.tld .
sftp> get .

So after entering the sftp command, you get an sftp> prompt, and simply enter get .. The -r option ensures that this will transfer the user's whole home directory tree, without following symlinks.

For large transfers it might be advisable to archive & compress old_server's home first. The old server will ask for a password; if that option has been disabled I'm sure the standard techniques for enabling key login apply, i.e. one would have to copy the appropriate keys from the local machine to new_server, or create new ones specifically for this.

Replacing

Before I replace the new server's www with the contents of the transfer/www directory, I go through everything there and check for files and folders that are now irrelevant (like logs, caches, software-specific files and folders etc.). I take even more care for other (hidden) files and directories located directly under the home folder.