A simple Mysql backup shell script _mysql

Source: Internet
Author: User
Tags mysql backup
#!/bin/bash #this is a script of MySQL backup if [!-d/mydata/data1/backup]; then mkdir/mydata/data1/backup fi CD 
 /mydata/data1/backup file=$ (find.-type f-mtime-7 | grep. *all.sql) #查找7天内是否有备份的文件 echo $file if [-Z $file]; then echo "Backup all Databases ..." backupfile=$ (date +%f-%h-%m-%s) mysqldump-uroot--lock-all-tables--flush-logs--master- data=2--all-databases >/mydata/data1/backup/"$backupfile-all.sql" if [$-eq 0]; then echo "Accomplish,file is $b
 Ackupfile-all.sql! "
 else echo "Failure!!!"
 Fi else #查找倒数第二大的二进制文件, make an incremental backup CD.
    echo "All database backups, now start doing incremental backups!"  A=1 b=1 for file in $ (LS |grep mysql-bin |grep-v index);d o num=$ (Echo $file |cut-d.-f2) If [ $num-gt $a];then a= $num fi unset num file num=1 for file in $ (LS |grep mysq L-bin |grep-v index);d o num=$ (Echo $file |cut-d.-f2) If [$num-gt $b-A $num-ne $a]; Then b= $num tmp= $file fi file1=$ (Echo $tmp |cut-d.-f1) file2=$ (Echo $tm p|cut-d-f2) Mysqlbinlog $tmp >/mydata/data1/backup/"$file 1-$file 2.sql" if [$-eq 0]; then echo "Backup Co Mpleted,file is "$file 1-$file 2.sql" "Fi fi

Description: This script does a full backup every seven days, a daily incremental backup, a full backup using the Mysqldump Client tool, and an incremental backup uses Mysqlbinlog to back up the binary log files.

Related Article

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.