Appendix A. MySQL Backup and Replication

Table of Contents

Database backups
Setting up replication
Repairing or starting a new replication node

Database backups

Semi related to replication is backups, here's a simple script that will copy the content of the database.

#!/bin/sh
mysqlhotcopy customerdb -u root -p *password* --record_log_pos=customerdb.mysql_replication_log_pos --allowold /data/backup/current/
tar cfjh /data/backup/current/backup.tar.bz /data0/backup/current/customer
mv /data0/backup/current/backup.tar.bz `date +"/data0/backup/custback_%Y_%m_%d.tar.bz"`

The above script works on Linux and does a complete backup of the entire database. It's recommended to have at least daily backups of the data. Keeping a copy of every day is also very convenient in case there is a corruption that has been unnoticed for some time, having older files to choose from when trying to find a clean copy can be invaluable.