Alister West

home is where your code is ...

DBA - Sync MyISAM replicas for Dev's

#!/bin/bash

# sync_repl2dev
# 
# Resync dev db's off live
#
# dev machine has 2 mysqls:
# - a replica of main_db
# - a dev mysql

# Install in crontab to run every monday morning.
#   0 1 * * mon /root/bin/sync > /dev/null

# Stop the main mysql
/usr/sbin/service mysql stop

# Stop replica main_db1
mysql -h 127.0.0.1 -P3311 -e 'stop slave; flush tables'

# Copy over myisam's from repl -> dev.
for i in backend frontend finance reports; do
    mkdir -p /var/lib/mysql/dev_${i}/ /var/lib/mysql/dev_${i}_old/
    rsync -avp --delete /var/lib/mysql/dev_${i}/* /var/lib/mysql/dev_${i}_old/*
    rsync -avp --delete /var/lib/mysql_db1/$i/* /var/lib/mysql/dev_${i}/
done;

mysql -h 127.0.0.1 -P3311 -e 'start slave'

# Repeat if necessary for any other replica's

/usr/sbin/service mysql start
By Alister West