mysql 备份脚本
以备份qunniao数据库为例
################################################################### # File Name: mysql_backup.sh # Author: xunyin # E-mail: lnhxzwb@126.com # Created Time: Fri 18 May 2019 05:01:02 PM CST #================================================================== #!/bin/bash # MYSQL备份脚本 mysql_back() { Date=$(date +%Y%m%d) HOST="127.0.0.1" NAME="root" PASSWD="123456" PORT="3306" DB="qunniao" #清除15天前数据 find ${path}/*.tar.gz -type f -mtime +15 -exec rm -rf {} \; #rm -rf ${path}/${DB}_$(($Date - 30)).tar.gz #保留30天数据 cd ${path} mysqldump -u${NAME} -p${PASSWD} ${DB}>${DB}_${Date}.sql echo "$Date 已成功备份数据库 ${DB}" > mysql_info.txt &>/dev/null tar -zcf ${DB}_${Date}.tar.gz ${DB}_${Date}.sql mysql_info.txt #发送邮件(mailx安装配置略) mailx -s "${DB}数据库备份成功" -a "${patch}/${DB}_${Date}.tar.gz" 'lnhxzwb@126.com'<mail_info.txt rm -rf ${DB}_${Date}.sql mysql_info.txt } path=/data/backup if [ -d ${path} ];then cd ${path} mysql_back else mkdir -p ${path} mysql_back fi
温馨提示:如无特殊说明,本站文章均为作者原创,转载时请注明出处及相应链接!