xtrabackup 遠程流備份腳本

一、xbstream 流,本地文件夾能夠本身建立,異地文件夾必須存在linux

 innobackupex --host=127.0.0.1  --post=3306 --stream=xbstream  --compress /root/backup/ | ssh root@192.168.56.15 "xbstream -x -C /tmp/"

二、xbstream 流,對端機器須要解壓並清理壓縮文件bash

192.168.56.15
xtrabackup --decompress --target-dir=/tmp/
find /tmp/ -name "*.qp" |xargs  rm -f

三、xbstream 流對端須要安裝軟件ssh

3.1 xtrabackupide

3.2 qpress-11-linux-x64.tarpost


四、腳本,週一全備,其它都是增備spa

[root@es1 chkpoint]# cat backup.sh
#!/bin/bash

[root@es1 chkpoint]# cat backup.sh 
LOCALDIR=/data/backup
CHECKPIONTDIR=$LOCALDIR/chkpoint
REMOTEDIR=/tmp/


WEEKDAY=`date +%u`
INTERVARNUM=`expr $WEEKDAY - 1`
TISHWEEKFULL=`date -d "$INTERVARNUM day ago" +%F`
TODAY=`date +%F`

ssh root@192.168.56.19 "mkdir -p /$REMOTEDIR/$TISHWEEKFULL"
ssh root@192.168.56.19 "mkdir -p /$REMOTEDIR/$TISHWEEKFULL/$TODAY"


if [ ! -f $CHECKPIONTDIR/xtrabackup_checkpoints ] ;then

echo "沒有lsn信息,開始一次全備"

innobackupex --host=127.0.0.1 --history  --post=3306 --stream=xbstream   --compress --extra-lsndir=$CHECKPIONTDIR  $LOCALDIR |ssh root@192.168.56.19 "xbstream -x -C /$REMOTEDIR/$TISHWEEKFULL/"
exit 1
fi


case $WEEKDAY in
#判斷變量WEEKDAY的值
    "1")

    innobackupex --host=127.0.0.1 --history  --post=3306 --stream=xbstream   --compress --extra-lsndir=$CHECKPIONTDIR  $LOCALDIR |ssh root@192.168.56.19 "xbstream -x -C /$REMOTEDIR/$TISHWEEKFULL/"        ;;
    "2")

       innobackupex --host=127.0.0.1  --post=3306 --stream=xbstream  --history     --incremental --extra-lsndir=$CHECKPIONTDIR  --incremental-basedir=$CHECKPIONTDIR   --compress $LOCALDIR | ssh root@192.168.56.19 "xbstream -x -C /$REMOTEDIR/$TISHWEEKFULL/$TODAY"

        ;;
        "3")

       innobackupex --host=127.0.0.1  --post=3306 --stream=xbstream  --history     --incremental --extra-lsndir=$CHECKPIONTDIR  --incremental-basedir=$CHECKPIONTDIR   --compress $LOCALDIR | ssh root@192.168.56.19 "xbstream -x -C /$REMOTEDIR/$TISHWEEKFULL/$TODAY"

        ;;
    "4")

       innobackupex --host=127.0.0.1  --post=3306 --stream=xbstream  --history     --incremental --extra-lsndir=$CHECKPIONTDIR  --incremental-basedir=$CHECKPIONTDIR   --compress $LOCALDIR | ssh root@192.168.56.19 "xbstream -x -C /$REMOTEDIR/$TISHWEEKFULL/$TODAY"

        ;;
        "5")

       innobackupex --host=127.0.0.1  --post=3306 --stream=xbstream  --history     --incremental --extra-lsndir=$CHECKPIONTDIR  --incremental-basedir=$CHECKPIONTDIR   --compress $LOCALDIR | ssh root@192.168.56.19 "xbstream -x -C /$REMOTEDIR/$TISHWEEKFULL/$TODAY"

        ;;
        "3")

       innobackupex --host=127.0.0.1  --post=3306 --stream=xbstream  --history     --incremental --extra-lsndir=$CHECKPIONTDIR  --incremental-basedir=$CHECKPIONTDIR   --compress $LOCALDIR | ssh root@192.168.56.19 "xbstream -x -C /$REMOTEDIR/$TISHWEEKFULL/$TODAY"

        ;;
    "4")

       innobackupex --host=127.0.0.1  --post=3306 --stream=xbstream  --history     --incremental --extra-lsndir=$CHECKPIONTDIR  --incremental-basedir=$CHECKPIONTDIR   --compress $LOCALDIR | ssh root@192.168.56.19 "xbstream -x -C /$REMOTEDIR/$TISHWEEKFULL/$TODAY"

        ;;

esac



五、tar 目前不支持增備,壓縮解壓須要注意,須要tar -xizvf  *.tar.gzrem

相關文章
相關標籤/搜索