Home  >  Article  >  Database  >  MySQL - MYSQL scheduled backup code example under Linux

MySQL - MYSQL scheduled backup code example under Linux

黄舟
黄舟Original
2017-03-14 16:45:021068browse

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

2. Modify /etc/crontab and customize the task plan Add

01 16 * * * root /home/lyz/DB_BAK/day_bak/day_bak.sh

to

/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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn