在/server/scripts/目錄中創(chuàng)建備份腳本MySQL_backup.sh
成都創(chuàng)新互聯(lián)專注于平湖網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供平湖營(yíng)銷型網(wǎng)站建設(shè),平湖網(wǎng)站制作、平湖網(wǎng)頁(yè)設(shè)計(jì)、平湖網(wǎng)站官網(wǎng)定制、微信小程序服務(wù),打造平湖網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供平湖網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。
#!/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 {} \;
===============================================================
創(chuàng)建定時(shí)任務(wù),每天凌晨2點(diǎn)執(zhí)行此腳本
# crontab -e
###### mysql backup at 2016/05/09 by ywliyq ######
0 2 * * * /bin/sh /server/scripts/mysql_backup.sh >/dev/null