#!/bin/bash
# Name:bakmysql.sh
# This is a ShellScript For Auto DB Backup and Delete old Backup
#备份地址
backupdir=/home/mysqlbackup
#备份文件后缀时间
time=_` date +%Y_%m_%d_%H_%M_%S `
#需要备份的数据库名称
db_name=test
#mysql 用户名
db_user=root
#mysql 密码
db_pass=123456
mysqldump -u $db_user -p$db_pass $db_name | gzip > $backupdir/$db_name$time.sql.gz
#删除一分钟之前的备份文件
find $backupdir -name $db_name"*.sql.gz" -type f -mmin +1 -exec rm -rf {} ; > /dev/null 2>&1
如果出现错误 /bin/bash^M: bad interpreter: No such file or directory
执行 sed -i "s/ //" filename 或sed -i "s/^M//" filename,直接将回车符替换为空字符串