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