Basic Server Migration Using SSH + SCP

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

The scenario here is that you have access to two servers - old and new - and you want to copy a site + database from old server to new server directly.

You have root SSH access to both servers.

1. Create a TAR archive of the document root for the site on the old server. Log into SSH on the old server.

Navigate to your vhost root (the folder just above httpdocs) then use the following command to make a tar archive of your entire httpdocs folder:


tar -cvvf httpdocs.tar httpdocs/

2. Gzip the TAR archive

 gzip httpdocs.tar

3. Transer the File to the New Server Log into SSH on the new server

This bit may change according to your specific server setups. The way I approached this was to log into the new server at the vhost root where I want to import the old httpdocs folder. I then use the following SCP command to log into the old server, find my archive and copy it to the current location.

I am using a custom port (not the real one in the example of course) for SSH so that must be specified. Unlike SSH, you must use a capital P to specify a custom port

Note the space and full stop at the end - they are very important!


scp -P 1111 old_server_username@123.123.123.123:/path/to/file/on/old/server/archive.tar.gz .

4. Dump all DB’s and Transfer To dump all of the databases into one single file we can use the following mysqldump syntax. Note you can simply use the –all-databases switch but this will backup database that you probably don’t want to include. Better to declare a list of all the DB’s that you do want.


mysqldump -u SomeUser -p --databases mydb1 mydb2 mydb3 > myDbs.sql

Once you have this dump file you can Gzip it and transfer it via SCP using the same kind of commands as above.


Tags: scp