#!/bin/bash #this is a script of MySQL backup if [!-d/mydata/data1/backup]; then mkdir/mydata/data1/backup fi CD
/mydata/data1/backup file=$ (find.-type f-mtime-7 | grep. *all.sql) #查找7天内是否有备份的文件 echo $file if [-Z $file]; then echo "Backup all Databases ..." backupfile=$ (date +%f-%h-%m-%s) mysqldump-uroot--lock-all-tables--flush-logs--master- data=2--all-databases >/mydata/data1/backup/"$backupfile-all.sql" if [$-eq 0]; then echo "Accomplish,file is $b
Ackupfile-all.sql! "
else echo "Failure!!!"
Fi else #查找倒数第二大的二进制文件, make an incremental backup CD.
echo "All database backups, now start doing incremental backups!" A=1 b=1 for file in $ (LS |grep mysql-bin |grep-v index);d o num=$ (Echo $file |cut-d.-f2) If [ $num-gt $a];then a= $num fi unset num file num=1 for file in $ (LS |grep mysq L-bin |grep-v index);d o num=$ (Echo $file |cut-d.-f2) If [$num-gt $b-A $num-ne $a]; Then b= $num tmp= $file fi file1=$ (Echo $tmp |cut-d.-f1) file2=$ (Echo $tm p|cut-d-f2) Mysqlbinlog $tmp >/mydata/data1/backup/"$file 1-$file 2.sql" if [$-eq 0]; then echo "Backup Co Mpleted,file is "$file 1-$file 2.sql" "Fi fi
Description: This script does a full backup every seven days, a daily incremental backup, a full backup using the Mysqldump Client tool, and an incremental backup uses Mysqlbinlog to back up the binary log files.