Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

#!/bin/bash
if [ $# -lt 3 ] ; then
echo "USAGE $0 slavename db_name type"
echo "slavename [e.g db2, db3, db4 ]"
echo "db_name [e.g db1 db2 etc... calm down one at a time]"
echo "type [xxl_table_array xl_table_array unwanted_table all_small]"
exit
fi

LOCKFILE="/tmp/pt_sync.lock"
if [ -e "${LOCKFILE}" ]; then
echo "Already running."
exit 99

else

echo $! > "${LOCKFILE}"
chmod 644 "${LOCKFILE}"
slavehost=$1
backup_dir="./$1-table-sync-`date +%Y-%m-%d-%H-%M`"
mkdir -p $backup_dir
table_size=$3
db=$2

get_list_of_tables()

{
case "$table_size" in
xxl_tables)
tbls="xxl_table_name"
;;
xl_tables)
tbls="xl_table_1 xl_table_2"
;;
large_tables)
tbls="large_table_1 large_table_2"
;;
unwanted_table)
tbls="temp_table1 temp_table2"
;;
all_small)
allsmalltable_sync
;;
*)
echo "chow chow; did you miss anything?"
;;
esac
}

execute_query()
{
for tb in $tbls; do
pt-table-sync h=db1,D=$db,t=$tb h=$slavehost --user=username --password=password --no-check-slave --print >> $backup_dir/$db-$tb.log

done
}
allsmalltable_sync()
{
tbls="$(mysql -Bse "use $db; show tables;" | grep -v 'all_but_shit_tables\|all_but_shit_table_2')"
for tb in $tbls; do
pt-table-sync h=db1,D=$db,t=$tb h=$slavehost --user=username --password=password --no-check-slave --print >> $backup_dir/$db-$tb.log

done
}

get_list_of_tables $2
execute_query
rm -f "${LOCKFILE}"

fi