增量备份
#!/bin/bash date=`date +%Y%m%d` logfile="/opt/dailybklog/"$date"dailybk.log" echo " " >>$logfile echo "=================================" >> $logfile echo $(date + "%y-%m-%d %H:%M:%S") >> $logfile echo "=================================">> $logfile time=$(date "-d 29 day ago" +"%Y%m%d%H%M%S") starttime=$(date "-d 1 day ago" +"%Y-%m-%d %H:%M:%S") mysql -uroot -pw0nder -h 192.168.10.X -e "flush logs" mysql -uroot -pw0nder -h 192.168.10.X -e "show slave status\G;" >>$logfile filename=`cat /opt/mysql/mysql-bin.index|awk -F "/" '{print $2}'` for i in $filename do echo "$starttime start backup binlog" >> $logfile mysqlbinlog -uroot -pw0nder -h 192.168.10.X --start-datetime="$starttime" /opt/mysql/$i >>/opt/binlogbk/daily$date.sql done if [$?=0] then find /opt/dailybklog/ -name "*.log" -type f -mtime +32 -exec rm{}\; >/dev/null 2>&1 echo "$date 10.Xdaily backup succeed " >>$logfile else echo " $date 10.Xdaily backup fail " >>$logfile fi cat $logfile |mail -s "$date 10.Xmysql dailybackupinfo" ~ 全备 #!/bin/bash time=`date "+%Y-%m-%d %H:%M:%S"` date=`date "+%Y%m%d"` echo "====================$time starting=====================" mysql -uroot -pw0nder -e "show slave status\G" >>/opt/fullbk.log mysql -uroot -pw0nder -e "show master status\G" >>/opt/fullbk.log echo "==============================================" >>/opt/fullbk.log mkdir /opt/mysqlfullbk/$date mysqldump -uroot -pw0nder cacti > /opt/mysqlfullbk/$date/cacti.sql echo "10.X mysql fullbk is ok" >>/opt/fullbk.log echo "=======================$time is finished=======================" >>/opt/fullbk.log cat /opt/fullbk.log |mail -s "10.X fullbk status"