innobackupex全量备份和增量备份脚本

# 每周六凌晨一次的全备份。

20 4 * * 6 /root/fullbackupdata.sh


数据库全备份的脚本

#!/bin/bash


dateformat=$(date +"%Y-%m-%d")


direc=/mnt/backup

fulldir=$direc/full


logdir=/home/backuplog

fulllog=$logdir/fulllog

applylog=$logdir/applylog


User=root

PassWord=root




for i in $fulllog $applylog $fulldir

do

        if [ ! -d $i ]; then

                mkdir -pv $i

        fi

done



if [ ! -d $fulldir/$dateformat ]; then

        innobackupex --user=$User --password=$PassWord --no-timestamp $fulldir/$dateformat >> $fulllog/fullbackup.log.$dateformat 2>&1 &

        #innobackupex --user=$User --password=$PassWord --apply-log --use-memory=1024MB  $fulldir/$dateformat >> $applylog/apply.log.$dateformat 2>&1 &

else

        echo "Don't backup database, because of directroy not found!" >> $logdir/error_full.log.$dateformat 2>&1 &

        exit 1

fi




# 每天一次的全增量(以全备份为基础的增量),每两个小时一次的增量备份(以全增量为基础的增量)

10 1-23/2 * * * /root/incrementbackupdata.sh


#!/bin/bash


# define some variables

User=root

PassWord=root

dateFull=$(date +"%Y-%m-%d")

datetime=$(date +"%Y-%m-%d")

dateIncre=$(date +"%Y-%m-%d_%H-%M-%S")


direc=/mnt/backup

fulldir=$direc/full

Increment=$direc/increment


logdir=/home/backuplog

incrementlog=$logdir/incrementlog


# The first incremental backup of a week's full backup.

if [ ! -d $Increment/$dateFull ]; then

        mkdir -p $Increment/$dateFull

        fullfilename=$(ls -lt $fulldir | sed -n 2p | awk '{print $9}')

        innobackupex --user=$User --password=$PassWord --use-memory=1024MB --no-timestamp --incremental $Increment/$dateFull/$datetime --incremental-basedir=$fulldir/$fullfilename >> $incrementlog/increment.log.$dateFull 2>&1 &

fi


# Incremental backups from the first incremental backups.

if [ -d $Increment/$dateFull/$dateFull ]; then

        cd $Increment/$dateFull

        fileName=$(ls -lt $Increment/$dateFull | sed -n 2p | awk '{print $9}')

        innobackupex --user=$User --password=$PassWord --use-memory=1024MB --no-timestamp --incremental $Increment/$dateFull/$dateIncre --incremental-basedir=$Increment/$dateFull/$fileName>> $incrementlog/increment.log.$dateIncre  2>&1 &

fi


本文转自 Tenderrain 51CTO博客,原文链接:http://blog.51cto.com/tenderrain/1748509

上一篇:邬贺铨:BAT做了美国做不了的互联网金融


下一篇:拧麻花,力出一孔 | 金蝶管易云2022年经营启动会圆满结束