mysql数据备份脚本

全库备份和增量备份

#!/bin/bash

BACKUP="/usr/bin/innobackupex --user=root --password=RCR8mGxnaNsb"
DIR_BASE=`/bin/ls -l -t /backup |/bin/awk '{print $9}'|grep ^[0-9]|head -1`
DIR_INCRE=`/bin/ls -l -t /backup/increment |/bin/awk '{print $9}'|grep ^[0-9]|head -1`

if [ $(date +%u) = 7 ];then
#删除上一次的全库备份
cd /backup/
rm -rf $DIR_BASE
sleep 600
#全库备份
$BACKUP /backup/
#对备份进行整理
cd /backup/
$BACKUP --apply-log $DIR_BASE

elif [ $(date +%u) = 1 ];then
cd /backup/
find . -mtime +6 -exec rm -rf {} \;

$BACKUP --incremental ./increment --incremental-basedir=/backup/$DIR_BASE

else 
cd /backup/increment/
/bin/find . -mtime +6 -exec rm -rf {} \;

$BACKUP --incremental . --incremental-basedir=$DIR_INCRE

fi

备份binlog

#!/bin/bash
cd /backup/log_bin
find . -mtime +10 -exec rm -rf {} \;
/usr/bin/rsync -az /data/mysqldata/salve20.00* /backup/log_bin/

  

posted @ 2018-08-25 13:46  人生信条~~  阅读(136)  评论(0编辑  收藏  举报