#!/bin/bash
rq=`date +%Y-%m-%d-%H` #日期
#数据库信息
host=127.0.0.1
user=root
password=xxx
dbname=script
#放在这个目录
path=/usr/local/backups/sql
mysqldump -h${host} -u${user} -p${password} --databases ${dbname} > ${path}/${dbname}${rq}.sql
#进入目录准备压缩
cd ${path}
# 压缩
tar -zcPvf ${dbname}${rq}.sql.tar.gz ${dbname}${rq}.sql
# 删除刚刚备份的sql文件,保留压缩文件
rm -f ${path}/${dbname}${rq}.sql
#for循环清除15天前日志
for rmfile in `find $path -mtime +14`;
do rm -f $rmfile;
done
标签:-%,rq,备份,mysql,sql,path,定时,dbname From: https://www.cnblogs.com/buckliu/p/17042973.html