脚本位置:/backup/mysqlbak.sh

#!/bin/bash  
# Name:bakmysql.sh  
# This is a ShellScript For Auto DB Backup and Delete old Backup  
#  
backupdir=/backup/mysqlbak  
time=` date +%Y%m%d%H `  
for dbname in  foan db1 db2 db3   
do  
    if [ ! -d $backupdir"/"$dbname ]  
    then mkdir -p $backupdir"/"$dbname  
    fi  
    echo -n "正在备份数据 $dbname"  
    mysqldump -h xxxx -u root -p'xxx' $dbname |gzip > $backupdir/$dbname/$dbname_$time.sql.gz  
    echo "[完成]"  
done  
echo "备份全部完成!"  
#  
find $backupdir -name "*.sql.gz" -type f -mtime +30 -exec rm {} \; > /dev/null 2>&1

备份路径:/backup/mysqlbak
备份定时:2 2 * * * /backup/mysqlbak.sh 1>/dev/null 2>/dev/null
备份策略:采用全量备份,每天凌晨2点2分开始备份,每个db数据库一个目录,保留30天日志。

最后修改:2023 年 11 月 09 日
如果觉得我的文章对你有用,请随意赞赏