Change webserver with minimal downtime

user1032531 asked:

I have a webserver in production. Its IP is and it is referred to as ServerA. In addition to storing script files, the server also stores user uploaded files and has a database. The application uses wildcard subdomains where,, etc go to a common virtual host, and the server code responds as appropriate given the subdomain name. I have my domain registrar pointing to IP and also set up to support wildcards.

I will need to change webservers to a new server with IP which it is referred to as ServerB.

What steps should be taken to migrate the servers with minimum downtime?

Below is my initial thoughts. Please comment if incorrect or if I am missing steps.

  1. Post notice on ServerA that the system will be down for maintenance.
  2. Setup Apache on ServerB similar to the setup on ServerA and also add another virtual host on ServerB with ServerName, (more on this later).
  3. Set up Apache on ServerA to display a down for maintenance page instead of accessing the application script.
  4. Copy script files, uploaded user files, and the database from ServerA to ServerB.
  5. Change domain registrar to point to IP
  6. Setup Apache on ServerA to redirect all requests to IP How will this work with the subdomain requirements?
  7. Wait for domain name changes to propagate. Will I be down during this time?
  8. After ServerB is fully tested, cancel service plan for ServerA.

My answer:

How about a zero downtime migration?

This is my general plan for such migrations:

  1. Set up an ad hoc VPN between the old server and the new server (e.g. with OpenVPN).
  2. Copy the entire application from the old server to the new server.
  3. Set up database replication between the old server and the new server, with the old server as master and the new server as slave, via the VPN.
  4. Wait for all databases to be replicated. This may take a while.
  5. Once replication is complete, connect directly to the new server (use the /etc/hosts trick) and verify that the application seems to work, that the web server is configured correctly, etc.
  6. Break the master/slave relationship and configure the application on the old server to talk to the database on the new server via the VPN.
  7. Change the DNS records. While waiting for the TTL to expire, some users will hit the old server and some will hit the new server, but both will use the database on the new server.
  8. When the TTL expires and the old server is no longer receiving traffic, decommission it. Take down the temporary VPN.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.