1.作成shell檔案
Shell檔:
DB_NAME='lyz' USER='root' PWD='root' TIME=$(date +%Y%m%d) DEL_TIME=$(date --date="7 days ago" +%Y%m%d) DB_BAK_NAME=tdc_debug${TIME}.sql DB_DEL_NAME=tdc_debug${DEL_TIME}.sql BACKUP_PATH='/home/zhaoqun/DB_BAK/day_bak/' echo $BACKUP_PATH$DB_BAK_NAME if test -f $BACKUP_PATH$DB_DEL_NAME then echo "Delete history dump file" rm -f $BACKUP_PATH$DB_DEL_NAME fi mysqldump -u $USER -p$PWD $DB_NAME>$BACKUP_PATH$DB_BAK_NAME
/etc/crontab 中追加
01 16 * * * root /home/lyz/DB_BAK/day_bak/day_bak.sh
每天的16:01 分進行MYSQL 備份,並保持7天的備份履歷。
以上是MySQL之-linux下MYSQL定時備分程式碼範例的詳細內容。更多資訊請關注PHP中文網其他相關文章!