MySQL binary log incremental backup footsteps

Source: Internet
Author: User
Tags mysql backup
The code is as follows Copy Code


#!/bin/bash
#定义用户名及密码
host=
User=
Userpwd=
#定义数据库
Database=

Mysqladmin-h$host-u$user Flush-logs
Daily_databakdir=/backdir
#定义MYSQL数据目录
Mysqldatadir=/mysql5.5/data

emailfile= $daily _databakdir/email.txt
#eMail =

date= ' DATE +%y%m%d%h%m%s '
logfile= $daily _databakdir/mysql$date.log
#echo         > $eMailFile
#echo----------------------->> $eMailFile
#echo $ (date + "%y-%m-%d%h:%m: %s ") >> $eMailFile
#echo-------
#
#------------------>> $eMailFile
time=$ (date" D ") Ago "+%y%m%d%h%m%s"
starttime=$ (date-d " -60 minute" + "%y-%m-%d%h:%m:%s")
Echo "Delete days before the log" &G t;> $eMailFile
mysql-h$host-u$user -E "purge master logs before ${time}" && echo "Delete days bef Ore log "|tee-a $eMailFile #删除10天前的2进制文件

Filename= ' cat $mysqlDataDir/mysql-bin.index |awk-f '/' {print $} ' # 2 files
For I in $filename
Todo
#echo "$StartTime start Backup Binlog" >> $eMailFile
mysqlbinlog-h$host-u$user-d $database--start-datetime= "$StartTime" $mysqlDataDir/$i >> $daily _databakdir/ Daily$date.sql |tee-a $eMailFile
Done
If [$? = 0]
Then

# Delete mtime>32 Incremental log backup file
Find $daily _databakdir-name "*.log"-type f-mtime +32-exec rm {}; >/dev/null 2>&1

CD $daily _databakdir
Tar-cvzf $daily _databakdir/$database $date.tar.gz daily$date.sql
# >>/dev/null 2&1
#scp to another server
echo "Daily backup succeed" >> $eMailFile
Else
echo "Daily backup fail" >> $eMailFile
#mail-S "MySQL Backup" $eMail < $eMailFile #备份失败之后发送邮件通知
Fi
Cat $eMailFile > $logFile


# Delete mtime>32 incremental log backup files
Find $daily _databakdir-name "*.log"-type f-mtime +32-exec rm {}; >/dev/null 2>&1

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.