Change Web Host Company Without Downtime (Linux or BSD oriented)

This outlines how to change web hosts with minimal downtime. It won’t go step by step, or explain, too much.

I’m using Hurricane Electric as my web host. I’ve been happy with them, especially after trying other web hosts that didn’t deliver the level of performance I needed. (I’m a return customer, having used them back in the 90s.)

Gather all passwords, making sure you can get into your accounts to manage domains, web server files, databases. Get these all in a single text file, for convenience.

Move the files over. If you can, use a tool like rsync, and run an rsync server on the originating server (or on the computer with a staging copy of the site). If you have shell access, you can write a script to sync the files. Here’s a bit of my script to sync:

#! /bin/bash
# this syncs everything except images
# necessary because rsync dies when there are too many files
for fn in action_icons admin atom audio authors calendar
do
        rsync -vr  rsync://zanon.slaptech.net/launionaflcio.org/docroot/${fn}/ public_html/$fn/
done

Move the database over. Again, if you have shell access, you can do this with a command like this:

#!/bin/bash
echo "getting database from remote"
ssh foobar@slaptech.net ./dump_mydb_org | mysql -pasdfsdf mydb

dump_mydb_org is a script that calls mysqldump with the correct username and password to dump mydb.

To get the application running on the new server, edit your local HOSTS file and create a line for your website. Typically, your website is hosted on www.mysite.com and mysite.com. What you will do is override the DNS, and create a new record for www.mysite.com. Set www.mysite.com to the new IP address.

In C:WINDOWSSYSTEM32DRIVERSETCHOSTS:

65.49.111.111 www.mysite.com

Going forward, www.mysite.com will point to the new server. You can now get the application working. Usually, that means altering configuration files so they can get to the new database.

If you have web stats, make sure they are working.

If you have to make updates to the old site, keep doing so, until Friday afternoon. On Friday afternoon, log into the new server, and run both sync scripts to sync the files and the database.

Then, alter the DNS records so your domains point to the new server.

In two to three days, nearly all the DNS records for your site will change over to the new server. On Monday morning, the new site should be getting all the traffic. From Friday evening to Monday morning, you should avoid updating the database. If you must, then, figure out some way to make sure you’re only touching the new website and database. Maybe put a file on the new server and read it through the web browser.

On Monday, download the logs from the old site. Shut it down, but don’t delete anything. You might need to switch back if the host turns out to suck.