[root@node1 scripts]# cat mysql_bak.sh
Backup_Dir=/data/backup/mysql/day
user=root
host=localhost
pwd=root
if [ ! -d $Backup_Dir ]
then
mkdir -p $Backup_Dir
fi
DB_Name=(
information_schema
achievements_statistical_utf8mb4
adv
cce
cheap
fnsj
fnsj_os
hdw
hf_oa_crm
hf_oa_sys
huofutp_msg_info
huofutp_oa_timer
huofutp_taobao_utf8mb4_draw
huofutp_utf8_accounting
huofutp_utf8_crm
huofutp_utf8_dbug_api
huofutp_utf8_developer
huofutp_utf8_exam
huofutp_utf8_hdw
huofutp_utf8_hr
huofutp_utf8_log
huofutp_utf8_msg
huofutp_utf8_okr
huofutp_utf8_report
huofutp_utf8_sys
huofutp_utf8_voice
huofutp_utf8_wiki
huofutp_utf8_workflow
huofutp_utf8mb4_office
jd_utf8mb4_template
jira
jwt
mysql
performance_schema
plugin
stylist_score
sys
taobaofuwu_utf8mb4_recommend
taobaofuwu_ylmf
test
test2
timer
timor
tuotuo_utf8mb4_cheap
tuotuo_utf8mb4_template
wangku_utf8mb4_ztdd
xxl_job
yctest
zzyj
)
_check() {
[ $? -ne 0 ] && exit 110
}
for ((i=0;i<=${#DB_Name[*]}-1;i++));
do
mysqldump -u$user -p$pwd -h$host --single-transaction --master-data=2 --routines --triggers --events --skip-tz-utc --set-gtid-purged=OFF --databases ${DB_Name[$i]} > ${Backup_Dir}/${DB_Name[$i]}-$(date +%F).sql
if [ -f $Backup_Dir/${DB_Name[$i]}-$(date +%F).sql ]
then
tar -czf $Backup_Dir/${DB_Name[$i]}-$(date +%F).sql.tar.gz $Backup_Dir/${DB_Name[$i]}-$(date +%F).sql --remove-files >>/dev/null 2>&1
fi
done
_check
find $Backup_Dir/* -ctime +4 -name "*.tar.gz" -exec rm -f {} \; > /dev/null
unset Backup_Dir
unset user
unset pwd