#!/bin/bash
#######################################################
# $Version: v1.0
# $Function: Shell Template Script
# $Author: Jerry.huang
# $organization: http://www.cnblogs.com/Mrhuangrui
# $Create Date: 2017-06-30 09:30
# $Description: You know what i mean,heiheihei
######################################################## Shell Env
SHELL_DIR="/opt/shell"
SHELL_LOG="${SHELL_DIR}/$0.log"
LOCK_FILE="/tmp/$0.lock"#Write Log
shell_log(){LOG_INFO=$1echo "$(date "+%Y-%m-%d") $(date "+%H-%M-%S") : $0 : ${LOG_INFO}" >> ${SHELL_LOG}
}# Shell Usage
shell_usage(){echo $"Usage: $0 {backup}"
}shell_lock(){touch ${LOCK_FILE}
}shell_unlock(){rm -f ${LOCK_FILE}
}# Backup MySQL All Database with mysqldump or innobackupex
mysql_backup(){if [ -f "$LOCK_FILE" ];thenshell_log "$0 is running"echo "$0" is running,exit now. && exitfishell_log "mysql backup start"shell_locksleep 10shell_log "mysql backup stop"shell_unlock
}# Main Function
main(){case $1 inbackup)mysql_backup;;*)shell_usage;esac
}#Exec
main $1