#!/bin/bash
# Error handling
function error()
{
echo -e "[ `date` ] $(tput setaf 1)$@$(tput sgr0)"
exit $2
}
### Set Bins Path ###
RM=/bin/rm
GZIP=/bin/gzip
GREP=/bin/grep
MKDIR=/bin/mkdir
MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump
MYSQLADMIN=/usr/bin/mysqladmin
### Enable Log = 1 ###
LOGS=1
### Default Time Format ###
TIME_FORMAT='%d%b%Y%H%M%S'
### Setup Dump And Log Directory ###
MYSQLDUMPPATH=/var/www/mysqldump
MYSQLDUMPLOG=/var/log/mysqldump.log
EXTRA_PARAMS=$1
#####################################
### ----[ No Editing below ]------###
#####################################
[ -f ~/.my.cnf ] || error "Error: ~/.my.cnf not found"
### Make Sure Bins Exists ###
verify_bins(){
[ ! -x $GZIP ] && error "File $GZIP does not exists. Make sure correct path is set in $0."
[ ! -x $MYSQL ] && error "File $MYSQL does not exists. Make sure correct path is set in $0."
[ ! -x $MYSQLDUMP ] && error "File $MYSQLDUMP does not exists. Make sure correct path is set in $0."
[ ! -x $RM ] && error "File $RM does not exists. Make sure correct path is set in $0."
[ ! -x $MKDIR ] && error "File $MKDIR does not exists. Make sure correct path is set in $0."
[ ! -x $MYSQLADMIN ] && error "File $MYSQLADMIN does not exists. Make sure correct path is set in $0."
[ ! -x $GREP ] && error "File $GREP does not exists. Make sure correct path is set in $0."
}
### Make Sure We Can Connect To The Server ###
verify_mysql_connection(){
$MYSQLADMIN ping | $GREP 'alive' > /dev/null
[ $? -eq 0 ] || error "Error: Cannot connect to MySQL Server. Make sure username and password are set correctly in $0"
}
### Make A Backup ###
backup_mysql_rsnapshot
backup_mysql_rsnapshot(){
local DBS="$($MYSQL -Bse 'show databases')"
local db="";
[ ! -d $MYSQLDUMPLOG ] && $MKDIR -p $MYSQLDUMPLOG
[ ! -d $MYSQLDUMPPATH ] && $MKDIR -p $MYSQLDUMPPATH
$RM -f $MYSQLDUMPPATH/* > /dev/null 2>&1
[ $LOGS -eq 1 ] && echo "" &>> $MYSQLDUMPLOG/rsnap-mysql.log
[ $LOGS -eq 1 ] && echo "*** Dumping MySQL Database At $(date) ***" &>> $MYSQLDUMPLOG/rsnap-mysql.log
[ $LOGS -eq 1 ] && echo "Database >> " &>> $MYSQLDUMPLOG/rsnap-mysql.log
for db in $DBS
do
local TIME=$(date +"$TIME_FORMAT")
local FILE="$MYSQLDUMPPATH/$db.$TIME.gz"
[ $LOGS -eq 1 ] && echo -e \\t "$db" &>> $MYSQLDUMPLOG/rsnap-mysql.log
if [ $db = "mysql" ]
then
$MYSQLDUMP --events --single-transaction $EXTRA_PARAMS $db | $GZIP -9 > $FILE || echo -e \\t \\t "MySQLDump Failed $db"
else
$MYSQLDUMP --single-transaction $db $EXTRA_PARAMS | $GZIP -9 > $FILE || echo -e \\t \\t "MySQLDump Failed $db"
fi
done
[ $LOGS -eq 1 ] && echo "*** Backup Finished At $(date) [ files wrote to $MYSQLDUMPPATH] ***" &>> $MYSQLDUMPLOG/rsnap-mysql.log
}
### Main ####
verify_bins
verify_mysql_connection
Could not execute Update_rows event on table db.table; Can't find record in 'table', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.262297, end_log_pos 1983208 As of my knowledge the causing stop of slave SQL thread error code of 1032, due to lack of sync between Master - Slave. In our case, slave got an Update event form master, but that particular record was not available in the slave. (Of course, that was deleted on Master n Slave separately) You would get this error only if the binlog_format is set to ROW_BASED or MIXED mode. So, now check that particular binlog at that position where replication stopped with this error. When you convert the binlog with mysqlbinlog command, you may see some junk characters where you were expecting some DMLs which caused the error(In our case its an Update statement). So you can use below command to translate binlog completely: mysqlbinlog --base64-output=DECO...
Comments
Post a Comment