My Database replication solution.

Earlier this morning I obviously had too much coffee so I started typing away at a solution I was looking at for a website that I’m currently hosting and supporting. The site is OZWRX and I have been hosting them coming up on two years and have had quite a lot input on how the site looks today. Recently there were a few issues in which the VPS that they were hosted on could no longer cope with the workload so it decides to take random breaks and won’t come back up. So I fucked that off and got them another VPS with twice the amount of guaranteed RAM. Anyways I wont go on about it, just read what I had to say to them…

I’ve been looking at solutions that will make sure that OZWRX website stays up in the event something happens to the original server that site is hosted on. I’ll try not to get too technical about it but it’s easy enough to understand.


OZWRX website goes down due to a problem with the host machine. Site is not accessible for hours. No way to access the server to restart, nobody available to be contacted. Bernard is losing his hair wondering if it’s the earthquake in Taiwan.

Proposed Solution:

Basically two different things need to be implemented here to ensure that the site is always accessible within minutes of the site going down.

First an exact copy of the website is setup in a different server not in the same geographical location or part of the same network. This is in case that city has been devastated by a natural disaster or any other acts of God. This copy of the website will have the same database and the database is completely in sync with the original website. This is called MYSQL database replication. What happens here is whatever content is posted in the original website gets automatically copied to the other website. Sounds fancy right! Not really all we are doing here is making sure that data exists in two separate locations so if there first one is destroyed an exact same copy is available from when it went down.

Think you so smart, so what if the second server goes down?

In the event that this happens, first thing the second server will do as soon as it comes back up will be to catch up on what it has missed out on and copy all the new data from the original website and syncs itself again. Nice! That’s some tricky shit!

Who backs up the second server?

An automated backup solution can be configured so that the second server will stop copying from the original website long enough to backup what it already has and then start up again to update itself. This can be done hourly, daily, weekly or monthly.

Now here comes the second part of this solution, if you haven’t already asked yourself how OZWRX members will get to the second server when the first one goes down, now is the time. All that fancy shit I wrote above is all well and good but we want to make it so that you don’t have to fucking do anything in your state of panic. :happy:

There is a service that you can pay for which costs less than a blowjob at your local brothel (speaking of which, Chris promised me a session at his favorite one which I haven’t seen yet) I’m on a roll so lets keep going. What this nifty little service will do is monitor the main website and as soon as it gets a whiff that it isn’t responding it will switch IP address to the second server, all of which is quicker than your average premature ejaculator. Brilliant!

At this stage you haven’t even done anything yet except to continue to scratch your balls, smile and say “That was fully sick Bro!!”

What just happened is the secondary server has taken the role of the primary server and this can be for as long as you like. But with everything, there is still a downside, let me explain. The service that switched you over to the secondary server will continue to monitor the primary server until it comes back up and it has the option to switch it back to the way it was BUT we don’t want that because the primary server will not have the data that the secondary one has. Posts will be lost and other unpleasant things can happen so the best thing to do is keep it the way it is and then switch the database replication roles of the two servers. So the primary becomes the secondary and vice versa. Make sense? As much as we like to not have to do anything, there is still some intervention required once things settle down. The secondary server needs to be set as “master” so that it doesn’t try to copy old data from the primary server when that one comes back up.

So there you have it a simple explanation to what I think you should consider now or in the near future.



The service that will switch your IP’s when the primary server goes down is only $14.95 USD a year.

Cost of the second server can be minimized to about half of your existing one. Approx: $40 USD with the same server specs.

Ron Gabriel
2:46 AM