天天看點

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

# define some variables

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

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

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

Increment=$direc/increment

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 &

# 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 &

本文轉自 Tenderrain 51CTO部落格,原文連結:http://blog.51cto.com/tenderrain/1748509