#!/bin/bash
# 定义备份使用的用户/密码
DbUser=root
DbPasswd=NTQ34tg*@19VF
# 定义备份的数据库.
DbName=("zabbix" "jumpserver" "n9e" "openfire")
# 定义备份目录
Path=/data
# 定义备份数据保存天数
Mtime=3
Time=$(date +%F)
if ! [ -d ${Path} ];then
mkdir ${Path}
fi
for i in ${DbName[@]};do
if [ -d ${Path}/${Time} ];then
cd ${Path}/${Time}
else
mkdir ${Path}/${Time} && cd ${Path}/${Time}
fi
mysqldump -f -u${DbUser} -p${DbPasswd} ${i} >${i}.sql
done
find ${Path} -name '*.sql' -mtime +${Mtime} |awk -F/ '{print $2}'|xargs rm -rf
# 定时任务 手动添加
# echo "0 1 * * * bash /root/db_backup.sh >> db_backup.log" >> /var/spool/cron/root```
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/database/276300.html