Best Practices for MySQL Replication Restore
So I'm looking at setting up MySQL Replication in a very basic master/slave setup. We're looking at this mainly for server failure rather than disaster recovery, so Im mostly interested in a failover. All of our applications are in PHP, so I imagine it would be fairly simple to just set something in the MySQL connect so that if the primary database can't be connected to, we'll write a file and fail over to the slave and use that.
My problem is in what the best practice for re-synching that data after the failover would be, or if there's a better solution.
The failover itself should be automated, but the restore process can be manual and we're looking to do this over WAN. Thanks in advance for the help
EDIT
After reading about Master/Master vs. Master/Slave architectures I'm not really any more clear on which setup is best for my scenario. The Databases themselves are fairly large (I don't have the exact size currently) and represent primarily transactional/log data (with some minor authentication and duplicate checking). For the most part rows aren't going to be altered, only added to the database.
My primary concern/usage for the replicated server is a failover, so while a Master-Master replication se开发者_运维知识库ems to be ideal for these purposes, reading up on those makes it sound as though once that failover actually happens, and records are added to database B, it's going to be more difficult to restore database A than in a Master-Slave relationship.
Items aren't deleted from either database except for during rollup/archiving and we can just add functionality to verify both servers are available during this time for a Master/Slave setup. 15-20 minutes of recovery time could be ok, in a disaster recovery situation where the failover had happened, but not on a consistant nightly basis. Hope those help bring clarity to the situation.
A lot of factors come in to place here. Depending on the size of the database, you can create an algorithm to grab what has changed (IE store the date/time when you move to the failover or the MAX id's) and just use that data to populate the new database. That would cause a problem, with deleted items. If items are actually deleted and do not just have a date set for when deleted.
Depending on the size, you can shutdown the site for maintenance for 15-30 minutes, do a SQL dump and just truncate the tables and re-import the data via the MySQL CLI interface, this can take some time, depending on the data.
Which is better, it all depends on your need. The latter, could potentially be scripted to where it can turn off the site for maintenance then fetch the data from FailOverServer to RegServer and then implement a series of MySQL commands to truncate the RegServer and import the data from FailServer once done Turn site back on.
I have never done it, so cannot speak to if it is a good way to go. But as long as no tables are modified on the FailOverServer, it should work fine.
精彩评论