## check mysql pid, and kill it checkProcess(){ PIDS=`ps -ef|grep mysqld|grep -v grep|grep 3306|awk '{print $2}'` if [ -n ${PIDS} ]; then for pid in ${PIDS} do kill -9 ${pid} done fi }
## check mysql service, make sure it's alive checkStatus(){ `mysqladmin ping > /dev/null 2>&1` if [[ $? != 0 ]]; then checkProcess echo "mysql is not alive,will be start now!" >> ${LOG_FILE} ${SHELL_DIR}/mysql_supervise.sh start >> ${LOG_FILE} 2>&1 fi `mysqladmin ping > /dev/null 2>&1` if [[ $? != 0 ]];then echo "Mysql server error" exit 1 fi }
## find all database name find_db_names(){ DB_NAMES_ALL=$(mysql -e "show databases;") index=0 for DB in ${DB_NAMES_ALL} do if [[ "$DB" != "Database" && "$DB" != "information_schema" && "$DB" != "performance_schema" ]];then db_names[$index]=$DB let index++ fi done }
## tgz file today exists,delete it delete_old_file(){ if [ -f $1 ]; then echo "[$1] Backup file is exists,will be delete" >> ${LOG_FILE} rm -f $1 > /dev/null 2>&1 fi }
## mysqldump function func_mysqldump(){ db_dump_file=$1$DUMP_FILE db_tgz_file=$1$TGZ_FILE
## backup all db backup_all(){ # find all db name find_db_names echo echo -e "Please enter the directory for save the backup file:" read dir if [[ ! -d $dir ]];then log_failure_msg "directory error!" exit 1 fi
echo cd $dir; mkdir $TIME; cd $TIME echo "Backup............." for arr in ${db_names[@]} do func_mysqldump $arr done echo "Finish" }
## backup one db user specified backup_one(){ # find all db name find_db_names echo echo -e "Please e