I spent most of Saturday moving Swap-bot to its new server. In the past, moving servers wasn’t too big a deal since I never really got any traffic. A day or two downtime wasn’t anything I worried about. But, the reason I had to even move in the first place was because Swap-bot has started to decent amount of traffic. On the old host, when Swap-bot would go down for a couple minutes I would hear about it from the users. With this move, a day or two downtime was not a real option. I luckily came up with something that resulted in about 2 minutes of downtime and it would have been shorter, but I took about a minute to track down a typo I made.
The reason coordination is even an issue is because changing a domain’s DNS records takes time to propagate throughout the internet. It isn’t instant and it doesn’t happen at the same time for all users. So at the exact same time one user could be browsing the new server and another could be browsing the old server because they are using different nameservers that have different information for my domain.
The first thing I had to do was setup the new server and test it. One mistake I made when setting up Swap-bot in the first place was setting up the SVN repository on the swap-bot.com domain. Once my DNS was changed, I would have no way of getting to the repository on the old server. So, the first thing I had to do was create a new repository on a different domain. The next step was to check out the swap-bot code and copy over all the user images from the old server. To copy everything over I chose to use rsync. rsync allowed me to copy everything over and then continually check for new images added throughout the day. Anything new that was added could easily be transfered over to the new server. Over the last year, we have accumulated nearly 1 GB of images, so copying the images over multiple times wasn’t something I really wanted to do. After transferring over a copy of the database to the new server, I added a record for the new server in my /etc/hosts file, telling my computer which IP address to use for swap-bot.com, instead of asking some other nameserver for it. This way, I could go in my browser to swap-bot.com and look at the new server. I found a few minor things that needed to be changed based on the way the new server is setup, but nothing major. It looked like everything was ready to go.
Then came the moment of truth. I was ready to make the switch. To do this, I setup my new mysql server to accept a remote connection from the old host. I then shut swap-bot down and transferred the database from the old server to the new one. Updated the database information on the old host and started swap-bot back up. At this point, swap-bot was now running on the old server, but pointing to the database on the new host. This way, I wouldn’t have to worry about any data syncing issues as DNS records changed at random throughout the next 24-48 hours. I gave a quick test of the old site and everything looked good, so I updated my DNS records to point to the new server.
It was actually a pretty uneventful move. I had a few people using AOL have a little trouble because, I think, they would get switched from one server to the other at random, but that was about it.
Categories: Internet, PHP, Programming