标签:UNC creation ESS base The logfile tar failed bin
#!/bin/bash
DUMP=/usr/bin/mysqldump
MYSQL=/usr/bin/mysql
IPADDR=127.0.0.1
PORT=3306
USER=abc
PASSWD=123456
DATABASE=test
ROOT_DIR=/data
LogFile=/var/log/mysqldunp.log
DATE=`date +%Y%m%d`
function info() {
echo -e "[`date +%Y-%m-%d\ %H:%M:%S`] - INFO " $@" " >> $LogFile
}
function error() {
echo -e "[`date +%Y-%m-%d\ %H:%M:%S`] - ERROR " $@" " >> $LogFile
}
function backup(){
table=$1
$MYSQLDUMP $DATABASE $table > ${OUTDIR}/${DATABASE}-${table}-${DATE}.sql
if [ $? == 0 ];then
info "${DATABASE} database ${table} table Backup successfully!"
else
error "${DATABASE}-${table} Backup failure"
fi
}
MYSQLCMD="$MYSQL -h$IPADDR -P$PORT -u$USER -p$PASSWD"
MYSQLDUMP="$DUMP -h$IPADDR -P$PORT -u$USER -p$PASSWD"
info "Database backup starts `date +%Y-%m-%d\ %H:%M:%S`"
OUTDIR=${ROOT_DIR}/mysql/${DATE}/${DATABASE}
[ -d $OUTDIR ] || mkdir -p $OUTDIR
if [ -d $OUTDIR ];then
info "Directory created successfully! -- ${ROOT_DIR}/mysql/${DATE}/${DATABASE}"
else
error "${ROOT_DIR}/mysql/${DATE}/${DATABASE} Directory creation failed."
error "Backup to terminate."
fi
table=(`$MYSQLCMD -e "show tables from $DATABASE;" | sed '1d'`)
info "tables : ${table[*]}"
for table in ${table[*]}
do
backup $table
done
标签:UNC creation ESS base The logfile tar failed bin
原文地址:https://www.cnblogs.com/outsrkem/p/11256950.html