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

MySQL - MYSQL scheduled backup code example under Linux

黄舟
Release: 2017-03-14 16:45:02
Original
1101 people have browsed it

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
Copy after login

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

01 16 * * * root /home/lyz/DB_BAK/day_bak/day_bak.sh
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template