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中文网其他相关文章!