#!/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
Add Run Permissions: chmod +x/etc/cron.daily/mysql-backup
Create backup file root folder: mkdir/mnt/tf-card/mysql-back/
Explanation: This script generates a backup folder every day,/mnt/tf-card/mysql-back/yyyy-mm-dd/xxxx.sql.gz. and hold the data for 15 days, and gzip compress the exported SQL file
View run time: Cat/etc/crontab
Folders can be changed on their own, MySQL Connection account user_root and user_pwd self-modification.
"# Backup MySQL Data file" This section of the statement can be added to 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.
Debian MySQL timed its own active backup script