#!/bin/bash db_user="root" db_passwd="dddddd " db_name="mmmmmm" cd /db_backup echo "you are in bakmysql directory now" backup_dir="/db_backup" #时间格式 time=$(date+ "%Y+%m+%d") #mysql备份命令 mysqldump -u$db_user -p$db_passwd $db_name > "$backup_dir/$db_name"-"$time.dump" echo "your database backup successfully completed" #删除7天前的备份文件 SevenDays=$(date -d -7days +"%Y%m%d") if [ -f /db_backup/ebkcmp-$SevenDays.dump] then rm -rf /db_backup/ebkcmp-$SevenDays.dump echo "you have delete the sql file" else echo "the sql file not exits" echo "bash completed" fi