Life is what happens to you while you're busy making other plans.
John Lennon

Where you need to transfer a web site between hosts not using the same control panel, you may need to set up the new account (domains, databases, mailboxes etc) and then copy files and databases between hosts. Exactly how you transfer files depends on what access you have to both hosting accounts – ideally you’ll have secure shell (ssh) access to both and you can make good use of the excellent linux command line tools. These are some example commands:

To backup a database on the old host, ready for transfer, ssh into the old account and:

mysqldump -u account_dbuser -p account_db >account_db.sql

This will create in the current directory a backup file of the database called account_db, using the database username account_dbuser – you will be prompted for this user’s password to access the database. If you don’t know these details look in the configuration file for your application.

To transfer files from old to new, ssh into the new account and:

rsync -avz* new_path/to/www/

Typically “path/to/www” will be something like “public_html/” or “domains/” – wherever the web-accessible files should go.

If both hosts are using the same log-analysis software (eg. the popular AWStats perl program) you may be able to transfer your historical visitor data files in the same way. Look for .html files in a directory called “stats” or “awstats” or ask your host for the correct location.

In some cases it may be possible to transfer mailboxes in the same way, but be very careful with this and if in doubt, don’t! Mail may be held in different file formats and file ownership / permissions can make this job difficult for a regular user. A better way to transfer mail is using an IMAP-capable e-mail client.

If you’re not already using IMAP then you probably don’t need to transfer mail at all – just set up the new mailboxes on the new account and use your mail client to download messages from both new and old mailboxes.

To transfer database dump files you can use rsync again or secure copy (scp). From the new account:

scp ./

This copies the database backup created earlier to the current directory.

To restore a database from the backup file in the new account (reverse of mysqldump earlier):

mysql -u account_dbuser -p account_db

Before using this you should have already created the database and the database user, eg. through the control panel. If you’re using CPanel note that this is a 3-stage process: Create database, create user, give user access to database – people often miss the final step).

The great advantage of the rsync command is that it can be used more than once. On the second and subsequent runs, the only files that will be transferred will be those that have changed since the last run. This makes it ideal for transferring web-sites with changing content, but if you’ve made changes to the files in order to make the site work properly on the new server then you need to protect those changed files – exclude them from the rsync process.

This is done by adding “–exclude=not/this/file” to the command for each file you want to exclude. If you changed the .htaccess file to put the site on the old server into maintenance mode, you probably also want to exclude that. Your rsync command line might become something like:

rsync -avz –exclude=old_path/to/www/.htaccess –exclude=old_path/to/www/* new_path/to/www/