#!/bin/bash
db_pass=xxxxx
db_host=192.168.1.x
db_user=root
db_port=xxxx
db_mysql=/usr/bin/mysqldump
#备份数据库名称
db_name=(
dataexa-insight-ccb
chao
test
mysql
)
#备份数据库路径
backup_location=/dataexa_sql
# 是否删除过期数据
expire_backup_delete="ON"
expire_days=7
backup_time=`date +%Y%m%d%H%M`
backup_dir=$backup_location
#判断是否有备份路径
if [ ! -d $backup_location ];then
mkdir -p $backup_location
fi
#备份sql数据
for i in ${db_name[@]}
do
$db_mysql -u$db_user -p$db_pass $i --skip-lock-tables > $backup_dir/${backup_time}_${i}.sql
done
# 删除过期数据
if [ "$expire_backup_delete" == "ON" -a "$backup_location" != "" ];then
`find $backup_location/ -type f -mtime +$expire_days | xargs rm -rf`
echo -e " $backup_time
Expired backup data delete complete!" >> $backup_dir/back.log
fi