添加自动任务每小时或者更短时间执行就好了
#!/bin/sh#author RuM#date 2015-07-10BAKDIR=/tmp/mysqlbak BAKDIR_FULL=$BAKDIR/full BAKDIR_ADD=$BAKDIR/add CONF=/etc/my.cnf passwd=123456 INNOBACKUPEX=/usr/bin/innobackupex
第一次执行会做一次全备跟增备,以后执行都会是增量备份
if [ -f "$INNOBACKUPEX" ] then if [ -d "$BAKDIR" ] then echo "is ok" else mkdir $BAKDIR_FULL -p mkdir $BAKDIR_ADD -p fi
全备
files=`ls $BAKDIR_FULL` if [ -z "$files" ] then $INNOBACKUPEX --defaults-file=$CONF --user=root --password=$PASSWD $BAKDIR_FULL FULLNAME=$(dir "$BAKDIR_FULL") $INNOBACKUPEX --defaults-file=$CONF --user=root --password=$PASSWD --incremental-basedir=$BAKDIR_FULL/$FULLNAME/ --incremental $BAKDIR_ADD else
增量备份
ADDNAME=$(ls -lt $BAKDIR_ADD |sed -n 2p|awk '{print $9}') $INNOBACKUPEX --defaults-file=$CONF --user=root --password=$PASSWD --incremental-basedir=$BAKDIR_ADD/$ADDNAME/ --incremental $BAKDIR_ADD fi else echo "is not install innobackupex"fi
The above is the detailed content of How to incrementally backup MySQL. For more information, please follow other related articles on the PHP Chinese website!