Debian MySQL timed automatic backup script

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.