1. 程式人生 > >mysql數據定期備份刪除

mysql數據定期備份刪除

fin 備份 article 腳本 dev 參考 tab mysq date

編寫shell腳本

#!/bin/bash
#
# This is a ShellScript For Auto DB Backup and Delete old Backup
#
backupdir=/webserver/mysqlbackup
time=` date +%Y%m%d%H `
/webserver/software/mysql/bin/mysqldump -u user -ppassword  ybjc | gzip > $backupdir/name$time.sql.gz

#delete
find $backupdir -name "name_*.sql.gz" -type f -mtime +5
-exec rm {} \; > /dev/null 2>&1

再給shell執行權限

執行crontab -e

15 11 * * * cd /home/loganalysis/ && ./dealexcel.sh >> /home/loganalysis/error.log 2>&1

重啟crontab

參考資料:http://blog.csdn.net/jkunzhang/article/details/7440215

http://blog.csdn.net/a120681076/article/details/51219277

mysql數據定期備份刪除