Mysql full and Incremental Backup scripts

Source: Internet
Author: User
Full data: [root @ masterleo] # catDBfullBak. sh #! Binbash # usemysqldumptofullybackupmysqldataBakDirrootleofullLogFilerootleofullbak. logDa ..

Full data: [root @ masterleo] # catDBfullBak. sh #! /Bin/bash # usemysqldumptofullybackupmysqldataBakDir =/root/leo/fullLogFile =/root/leo/full/bak. logDa ..

Full:

[Root @ master leo] # cat DBfullBak. sh #! /Bin/bash # use mysqldump to fully backup mysql dataBakDir =/root/leo/fullLogFile =/root/leo/full/bak. logDate = 'date + % Y % m % d' Begin = 'date + "% Y % m month % dday % H: % M: % S "'CD $ BakDirDumpFile = $ Date. sqlGZDumpFile = $ Date. SQL. tests-uroot-p123456 -- all-databases -- lock-all-tables -- routines -- triggers -- events -- master-data = 2 -- flush-logs> $ DumpFiletar zcvf $ GZDumpFile $ DumpFilerm $ dumpFileLast = 'date + "% Y % m % d % H: % M: % S "'echo start: $ Begin end: $ Last $ GZDumpFile succ >>$ LogFile

Parameter notes:

-- All-databases # Back up all databases -- lock-all-tables # apply a read lock to all tables -- routinge # stored procedures and functions -- triggers # Trigger -- events # record events -- master-data = 2 # record the location of the current binary log in the backup file, and it is annotated. 1 is meaningful only when it is not commented out in master-slave replication -- flush-logs # the log is rolled once.

The result is as follows:

[Root @ master full] # ls20140728. SQL. tgz bak. log [root @ master full] # cat bak. log start: July 28, 2014 19:02:59 end: July 28, 2014 19:02:59 20140728. SQL. tgz succ start: July 28, 2014 19:12:01 end: July 28, 2014 19:12:01 20140728. SQL. tgz succ [root @ master full] #

Incremental Backup:

[Root @ master leo] # cat DBDailyBak. sh #! /Bin/basw.kdir =/root/leo/binlog/BinDir =/var/lib/mysqlLogFile =/root/leo/binlog/bak. logBinFile =/var/lib/mysql/mysql-bin.indexmysqladmin-uroot-p123456 flush-logsCounter = 'wc-l $ BinFile | awk '{print $1} ''NextNum = 0for file in' cat $ BinFile 'do base = 'basename $ file' 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 else cp $ BinDir/$ base $ BakDir/echo $ base copying >>$ LogFile fi fidoneecho 'date + "% Y % m % d % H: % M: % S "'$ Next Bakup succ ~ >>$ LogFile


This article is from the "" blog. Be sure to keep this source

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.