Backup strategy:
Make a full standby every Sunday and make an incremental backup every day.
One: Fully-prepared script
Cat xtrabackup_full.sh
#!/bin/bash
Local_ip= "$ (/sbin/ifconfig eth0|grep ' inet addr ' |awk-f: ' {print $} ' |cut-d '-f1)"
Email= ' pingping1990429@163.com '
User= ' Root '
Passwd= ' system@123 '
my_config= '/etc/my.cnf '
log=$ (date +%y%m%d%h%m). log
str=$ (date +%y%m%d%h%m). tar.gz
Backup_dir= '/backup/mysql/xtrabackup '
Source= ' pingping1990429@163.com '
target= ' yabingshi@163.com '
title= ' xtrabackup information '
Mailuser= ' pingping1990429 '
Mailpassword= ' jyp20100 '
content1= ' server_name: ' $ (hostname) ' server_ip: ' $local _ip ' $ (date + "%y-%m-%d%h:%m:%s") ' MySQL full backup success! '
content2= ' server_name: ' $ (hostname) ' server_ip: ' $local _ip ' $ (date + "%y-%m-%d%h:%m:%s") ' MySQL full backup faild! '
echo "Start to backup at $ (date +%y%m%d%h%m)"
if [!-d "$backup _dir"];then
Mkdir-p $backup _dir
Fi
#innobackupex--defaults-file= $my _config--user= $user--password= $passwd--database= $database--stream=tar $backup _ Dir 2> $backup _dir/$log | Gzip 1> $backup _dir/$str
Innobackupex--defaults-file= $my _config--user= $user--password= $passwd $backup _dir
If [$?-eq 0];then
echo "Backup is finish! At $ (date +%y%m%d%h%m)
echo "server_name:$ (hostname) SERVER_IP: $local _ip $ (date +"%y-%m-%d%h:%m:%s ") MySQL full backup success!"
/usr/local/bin/sendemail-f $source-T $target-S smtp.163.com-u $title-xu $MailUser-xp $MailPassword-M $content 1
Exit 0
Else
echo "Backup is fail! At $ (date +%y%m%d%h%m)
echo "server_name:$ (hostname) SERVER_IP: $local _ip $ (date +"%y-%m-%d%h:%m:%s ") MySQL full backup fail!"
/usr/local/bin/sendemail-f $source-T $target-S smtp.163.com-u $title-xu $MailUser-xp $MailPassword-M $content 2
Exit 1
Fi
echo "Backup Process Done"
Two: Incremental backups
[Root@single download]# Cat xtrabackup_incremental.sh
#!/bin/bash
#增量备份依赖于前一天的备份, so if the backup fails the day before, the subsequent fails.
Local_ip= "$ (/sbin/ifconfig eth0|grep ' inet addr ' |awk-f: ' {print $} ' |cut-d '-f1)"
Email= ' pingping1990429@163.com '
User= ' Root '
Passwd= ' system@123 '
my_config= '/etc/my.cnf '
log=$ (date +%y%m%d%h%m). log
str=$ (date +%y%m%d%h%m). tar.gz
Backup_dir= '/backup/mysql/xtrabackup '
Source= ' pingping1990429@163.com '
target= ' yabingshi@163.com '
title= ' xtrabackup information '
Mailuser= ' pingping1990429 '
Mailpassword= ' jyp20100 '
content1= ' server_name: ' $ (hostname) ' server_ip: ' $local _ip ' $ (date + "%y-%m-%d%h:%m:%s") ' MySQL incremental backup Success! '
content2= ' server_name: ' $ (hostname) ' server_ip: ' $local _ip ' $ (date + "%y-%m-%d%h:%m:%s") ' MySQL incremental backup faild! '
last_day=$ (date-d "1 days Ago" +%y-%m-%d)
today=$ (Date +%y%m%d)
filename=$ (Find $backup _dir-name "$last _day*"-print|awk-f/' {print $NF} ')
echo "Start to backup at $ (date +%y%m%d%h%m)"
if [!-d "$backup _dir"];then
Mkdir-p $backup _dir
Fi
#innobackupex--defaults-file= $my _config--user= $user--password= $passwd--stream=tar $backup _dir 2> $backup _dir/$ Log | Gzip 1> $backup _dir/$str
Innobackupex--defaults-file= $my _config--user= $user--password= $passwd--incremental $backup _dir- incremental-basedir= $backup _dir/$filename
If [$?-eq 0];then
echo "Backup is finish! At $ (date +%y%m%d%h%m)
echo "server_name:$ (hostname) SERVER_IP: $local _ip $ (date +%y-%m-%d%h:%m:%s)" MySQL Incremental backup success! "
/usr/local/bin/sendemail-f $source-T $target-S smtp.163.com-u $title-xu $MailUser-xp $MailPassword-M $content 1
Exit 0
Else
echo "Backup is fail! At $ (date +%y%m%d%h%m)
echo "server_name:$ (hostname) SERVER_IP: $local _ip $ (date +%y-%m-%d%h:%m:%s)" MySQL Incremental backup fail! "
/usr/local/bin/sendemail-f $source-T $target-S smtp.163.com-u $title-xu $MailUser-xp $MailPassword-M $content 2
Exit 1
Fi
echo "Backup Process Done"
Three: The combination of crontab to achieve automatic backup
0 0 * * 0/download/xtrabackup_full.sh>>/download/xtrabackup_full.log 2>&1
0 0 * * 1-6/download/xtrabackup_incremental.sh>>/download/xtrabackup_incremental.log 2>&1
--This article references from: http://www.aixchina.net/home/space.php?uid=408689&do=blog&id=147879