1, MySQL full-scale backup, incremental backup. Turn on MySQL's logbin log feature. Add the following code to the/etc/my.cnf file:
[Mysqld]
Log-bin = "/home/mysql/logbin.log"
Binlog-format = ROW
Log-bin-index = "/home/mysql/logindex"
binlog_cache_size=32m
max_binlog_cache_size=512m
max_binlog_size=512m
restart MySQL . users and groups with path/home/mysql are changed to MySQL.
2. Incremental backup
Create the following directory under the/home/mysql/directory:
Mkdir-p/home/mysql/backup/daily
Incremental backup Script
Cd/home/mysql
VI binlogbak.sh
#!/bin/bash
Export. UTF-8
Bakdir=/home/mysql/backup/daily
Bindir=/home/mysql
Logfile=/home/mysql/backup/binlog.log
Binfile=/home/mysql/logindex.index
Mysqladmin-uroot-proot123flush-logs
# This is used to generate a new mysql-bin.00000* file
Counter= ' wc-l $BinFile |awk ' {print '} '
Nextnum=0
# This for loop is used to compare $Counter, $NextNum These two values to determine whether the file is present or up to date.
For file in ' Cat $BinFile '
Do
Base= ' basename $file '
#basename used to intercept the mysql-bin.00000* file name and remove the./mysql-bin.000005 front .
nextnum= ' expr $NextNum + 1 '
If [$NextNum-eq $Counter]
Then
Echo $base skip! >> $LogFile
Else
dest= $BakDir/$base
if (test-e $dest)
#test-E is used to detect if the target file exists and is written exist! Go to the $LogFile .
Then
Echo $base exist! >> $LogFile
Else
CP $BinDir/$base $BakDir
echo $base copying >> $LogFile
Fi
Fi
Done
Echo ' date + '%Y year %m month %d day %h:%m:%s "' Bakup succ! >> $LogFile
give binlogbak.sh Execute Permissions
chmod a+x/home/mysql/binlogbak.sh
3, full-scale backup
VI databak.sh
#!/bin/bash
Export. UTF-8
Bakdir=/home/mysql/backup
Logfile=/home/mysql/backup/bak.log
Date= ' Date +%y%m%d '
begin= ' date + '%Y year %m month %d day %h:%m:%s "'
CD $BakDir
dumpfile= $Date. sql
gzdumpfile= $Date. sql.tgz
Mysqldump-uroot-proot123--all-databases--flush-logs--delete-master-logs--single-transaction > $DumpFile
TAR-CZVF $GZDumpFile $DumpFile
RM $DumpFile
count=$ (ls-l *.tgz |wc-l)
If [$count-ge 5]
Then
file=$ (ls-l *.tgz |awk ' {print$9} ' |awk ' Nr==1 ')
Rm-f $file
Fi
# Keep database content for the last four weeks only
last= ' date + '%Y year %m month %d day %h:%m:%s "'
echo start : $Begin end : $Last $gzdumpfile succ >> $LogFile
CD $BakDir/daily
Rm-f *
give databak.sh Execute Permissions
chmod a+x/home/mysql/databak.sh
4. Start the scheduled task
Crontab-e
# every Sunday morning the full backup script is executed
0 3 * * 0/home/mysql/databak.sh >/dev/null 2>&1
# Monday to Saturday early morning --to do an incremental backup
0 3 * * 1-6/home/mysql/binlogbak.sh >/dev/null 2>&1
Make the above scheduled tasks effective
Crontab/etc/crontab
View Scheduled Tasks
Crontab-l
Complete.
This article is from the "Light Dust" blog, please be sure to keep this source http://857803451.blog.51cto.com/12777961/1950242
Responsible for database backup, Monday Saturday incremental backup, Sunday full-scale backup