1. Create a shell file
Shell file:
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
01 16 * * * root /home/lyz/DB_BAK/day_bak/day_bak.sh
/etc/crontab to perform MYSQL backup at 16:01 every day and keep the backup history for 7 days.
The above is the detailed content of MySQL - MYSQL scheduled backup code example under Linux. For more information, please follow other related articles on the PHP Chinese website!