共计 1044 个字符,预计需要花费 3 分钟才能阅读完成。
**!/bin/bash
备份 MySQL 数据
保存 10 天备份数据
currentpath=`dirname $0`
if [${currentpath} == '.' ];then
currentpath=`pwd`
fi
backup_path=/backup/mysql
suffix=`date "+%F"`
logfile=${currentpath}/logs/mysqlbacklog.log
mysql_user=root
mysql_password=xxxxx
mysqldump_prog=/usr/local/mysql/bin/mysqldump
mysql_sock=/tmp/mysql.sock
[! -d ${backup_path} ] && mkdir -p ${backup_path}
echo "==============================================" >> ${logfile}
echo "`date "+%F %H:%M:%S"` 开始备份 MySQL 数据 " >> ${logfile}
cd ${backup_path}
${mysqldump_prog} -u${mysql_user} -p${mysql_password} -S ${mysql_sock} -A -B -x -F --master-data=2 -E -R --triggers |gzip >${backup_path}/all-${suffix}.sql.gz
if [$? -ne 0];then
echo "`date "+%F %H:%M:%S"` 备份 MySQL 数据失败 " >> ${logfile}
else
echo "`date "+%F %H:%M:%S"` 备份 MySQL 数据成功, 备份文件名:${backup_path}/all-${suffix}.sql.gz" >> ${logfile}
fi
echo "`date "+%F %H:%M:%S"` MySQL 数据备份结束 " >> ${logfile}
echo "==============================================" >> ${logfile}
cd ${backup_path}
find ${backup_path} -mtime +10 -exec rm -f {} \; # 删除七天以前的备份数据 </pre>**
mysql 数据库备份脚本打包并删除几天前的备份数据
基本就是上面的写法了. 大神写的脚本!
正文完