I've got daily backups of one of my sites that are automatically sent to another server. If my site goes down on one server, I just forward the domain to the other IP address and the site's as good as new. Only, I can't figure out a good way to sync the database. I want to grab the current database contents and sync a database on another server to "mirror" my existing database on my main site daily. I've found cronjobs and scripts that will automatically backup my database, but I don't have anything that would automatically import its contents into another database. Any ways of doing this??
hi, try the mysql tool "mysqldump". on the mainserver do: mysqldump --opt db_name | mysql --host=remote_host -C db_name
You should look into replication. Every time the master database gets an update the slave database is updated as well. This way your databases never have different data on them, and if the master goes down, you don't lose any information due to a gap in syncing. MySQL uses a binlog replication which is a bit of a pain to understand and configure, but once it's setup, it's a lot more reliable than dumping the existing database to the other server every day.
Thats what I want to do, but the slave database will reside on a different server, in case the master server goes down.
This is what you do in replication. You can easily setup MySQL master/slave replication if you follow the steps. The only time taking thing is taking dump from the master and importing it to the slave.
That is what i find for a long time. Is it call mirror server like big site use it? when one server down, visitor can still visit your site,right?
Sort of. If you are simply replicating a database it wont provide any more redundancy than a single server. You have to either program into the site to use the second database if it can't connect to the master database or use a load balance / fail-over system that will swap the databases in the case that one goes down. It gets quite a bit more complicated to implement a fail-over system than just replication.