#!/bin/shlog=/var/log/mysql-backup.log# MySQL db infouser_root=xxxxxxuser_pwd=xxxxxxx# mysql data stored dirTODAY= ' Date +%f ' storedir=/mnt/tf-card/mysql-back/$TODAYmkdir $STOREDIRecho "* * * PATH: $STOREDIR mysql-backup * * *" >> $ log# Delete Overtime backup filesrm-rf/mnt/tf-card/mysql-back/$ (date +%f--date= ' days ago ') # Backup MySQL data filemy Sqldump-u$user_root--password= $USER _pwd--databases my_yd_net--lock-all-tables--flush-logs |gzip> $STOREDIR/my_ Yd_net.sql.gz
------------------
Create script: Nano/etc/cron.daily/mysql-backup
Increase execution permissions: chmod +x/etc/cron.daily/mysql-backup
Create backup file root directory: mkdir/mnt/tf-card/mysql-back/
Explanation: This script generates a backup directory every day,/mnt/tf-card/mysql-back/yyyy-mm-dd/xxxx.sql.gz, and holds data for 15 days, and compresses the exported SQL file with gzip
View execution Time: Cat/etc/crontab
Directory can be modified by itself, MySQL Connection account user_root and user_pwd self-modification;
"# Backup MySQL Data file" This section of the statement can add multiple mysqldump backup statements, backup multiple libraries at one time.
Data processing for more than 15 days: Every day an attempt is to delete a file before the 15th day.