MySQL Incremental backup script

Source: Internet
Author: User

#!/bin/bash

bakdir=/home/webdata/mysqlbackup/mysqlbackup_log/

bindir=/home/mysql/var/

Logfile=/home/webdata/mysqlbackup/mysqlbackup_log/bak.log

Binfile=/home/mysql/var/mysql-bin.index

Mysqldump-udearedu-p--lock-tables--flush-logs--master-data=1 vkt >/home/webdata/mysqlbackup/mysqlbackup_log/ Vkt.backup

# # # Refresh the log, generate a new log and copy it to the appropriate directory

Counter= ' wc-l $BinFile |awk ' {print $} ' # # # is calculated inside the bin-log index. Binlog number of logs

Nextnum=0

For file in Cat $BinFile '

Do

Base= ' basename $file ' get rid of./File name

nextnum= ' expr $NextNum + 1 '

If [$NextNum-eq $Counter]

Then

Echo $base skip! >> $LogFile

Else

dest= $BakDir/$base

if (test-e $dest)

Then

Echo $base exist! >> $LogFile # # # # Skip the last bin_log log because the last log is being recorded

Else

CP $BinDir/$base $BakDir

echo $base copying >> $LogFile

Fi

Fi

Done

/usr/bin/expect<<eof

# # # introduced expect, for interactive login, ordinary Shell script can not be interactive, enter password automatically login mysql

# # #下面是自动拷贝到备份服务器

Set timeout 300;

Spawn Scp-r $BakDir 192.168.0.90:/sde/50_mysqlbackup

Expect "*password:"

Send "password\r"

Sleep 1

Expect 1

Expect EOF

Eof


This article is from the "full of Handsome Technology blog" blog, please be sure to keep this source http://manyushuai.blog.51cto.com/8818545/1733283

MySQL Incremental backup script

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.