mysql 备份
1.安装innobackup 备份工具
2.次备份脚本一周一个全备,六天是增量备份,脚本如下:
1 #!/bin/bash 2 #Every 14 times the backup for a cycle 3 4 format_time=`date +"%Y-%m-%d_%H:%M:%S"` 5 week=`date +%w` 6 backupbin=/usr/bin/ 7 backdir=/export/mysql_backup 8 tardir=/export/mysql_backup/beifen 9 tarback=`date +"%Y-%m-%d"`10 file_cnf=/etc/my.cnf11 user_name=root12 password=12313 db="bridge bridgemini xr_wp bridgecharge"14 out_log=$backdir/xtrabackup_log15 time_cost=$backdir/timecost.txt16 tar_cost=$backdir/tarcost.txt17 bakdate=`date +"%m-%d"`18 num_file=`ls -1 $tardir|wc -l`19 ###########################################20 #yesterday=`date -d "yesterday" +"%m-%d"` #21 #ENDTIME=`date +"%Y-%m-%d %H:%M:%S"` #22 #begin_date=`date -d "$BEGINTIME" +%s` #23 #end_date=`date -d "$ENDTIME" +%s` #24 #spendtime=`expr $end_date - $begin_date` #25 ###########################################26 27 if [ ! -d "$backdir" ];then28 mkdir -p $backdir29 fi30 31 32 if [ ! -d "$tardir" ];then33 mkdir -p $tardir34 fi35 36 if [ -f "$tardir/rec7.tar.gz" ];then 37 mkdir -p $tardir/$tarback38 mv $tardir/*.tar.gz $tardir/$tarback39 fi40 41 42 if [ -d "$backdir/rec7" ];then43 tar -zcvf $tardir/backup_$bakdate.tar.gz $backdir/* --exclude beifen44 rm -rf $backdir/full $backdir/rec* $backdir/*.txt45 fi46 if [ $num_file -ge 3 ]; then47 rm -r `ls -rt $tardir/*|head -n1`48 fi49 50 51 #Full backup 52 53 if [ ! -d "$backdir/full" ];then54 BEGINTIME=`date +"%Y-%m-%d %H:%M:%S"`55 echo "##### Full backup at $BEGINTIME start" >> $time_cost56 innobackupex --defaults-file=$file_cnf --no-timestamp --user=$user_name --password=$password --socket=/tmp/mysql.sock $backdir/full 1> $out_log.full_$format_time.txt 2>&157 ENDTIME=`date +"%Y-%m-%d %H:%M:%S"`58 echo " It takes full backup at $ENDTIME END" >> $time_cost59 begin_date=`date -d "$BEGINTIME" +%s`60 end_date=`date -d "$ENDTIME" +%s`61 spendtime=`expr $end_date - $begin_date`62 echo " Run time full backup $spendtime sec " >> $time_cost63 `cat $time_cost |mail -s 'mysql backup time' wangshj@quanjing.com`64 exit 065 fi66 67 i=168 while [ ${i} -lt 14 ];do69 # The No.$i incremental backup!!70 if [ ! -d "$backdir/rec$i" ];then 71 BEGINTIME=`date +"%Y-%m-%d %H:%M:%S"`72 echo "##### The No.$i incremental backup at $BEGINTIME Start!" >> $time_cost73 innobackupex --defaults-file=$file_cnf --no-timestamp --user=$user_name --password=$password --socket=/tmp/mysql.sock --incremental $backdir\/rec$i --incremental-basedir=$backdir/full 1> $out_log.rec$i.$format_time.txt 2>&174 ENDTIME=`date +"%Y-%m-%d %H:%M:%S"`75 echo "It takes rec$i backup at $ENDTIME END!" >> $time_cost76 begin_date=`date -d "$BEGINTIME" +%s`77 end_date=`date -d "$ENDTIME" +%s`78 spendtime=`expr $end_date - $begin_date`79 echo "Run time No.$i $spendtime sec! " >> $time_cost80 `cat $time_cost |mail -s 'mysql backup time' wangshj@quanjing.com`81 exit 082 fi83 i=`expr $i + 1`84 done