mysqldump备份数据库,并删除7天前的备份文件脚本
在/server/scripts/目录中创建备份脚本MySQL_backup.sh
成都创新互联专注于平湖网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供平湖营销型网站建设,平湖网站制作、平湖网页设计、平湖网站官网定制、微信小程序服务,打造平湖网络公司原创品牌,更为您提供平湖网站排名全网营销落地服务。
#!/bin/bash # --------------------------- # Filename: mysql_backup.sh # Revision: 1.4 # Date: 2016/05/09 # Author: ywliyq # Email: ywliyq@163.com # Website: http://ywliyq.blog.51cto.com/ # Description: mysql backup every day delete before 7days. # Notes: This plugin uses the "" command # ---------------------------- # Copyright: 2016 (c) ywliyq # License: GPL # ---------------------------- # Backup file is saved in the directory, if it does not exist Create basepath='/data/mysql/backup/' if [ ! -d "$basepath" ]; then mkdir -p "$basepath" fi # mysql bakcup to /data/mysql/backup/ /application/mysql/bin/mysqldump -uroot -p'12345677' --events --ignore-table=mysql.events -F -B -A|gzip >$basepath/mysqlbak_$(date +%F).sql.gz # Delete the backup data to 7 days before find $basepath -mtime +7 -name "*.sql.gz" -exec rm -rf {} \;
===============================================================
创建定时任务,每天凌晨2点执行此脚本
# crontab -e
###### mysql backup at 2016/05/09 by ywliyq ######
0 2 * * * /bin/sh /server/scripts/mysql_backup.sh >/dev/null
当前名称:mysqldump备份数据库,并删除7天前的备份文件脚本
文章起源:http://ybzwz.com/article/gdeeee.html