xtradbbackup 자동 증량 백업 데이터베이스 구현(업데이트 1)
#!/bin/bash
#on xtrabackup 2.2.8
# ,
# ,
INNOBACKUPEX_PATH=innobackupex #INNOBACKUPEX
INNOBACKUPEXFULL=/usr/bin/$INNOBACKUPEX_PATH #INNOBACKUPEX
#mysql
#MYSQL_CMD="--host=192.168.8.70 --user=root --password=xiaozhao1 --port=3306"
TMPLOG="/tmp/innobackupex.$$.log"
MY_CNF=/etc/my.cnf #mysql
MYSQL=/usr/bin/mysql
MYSQL_ADMIN=/usr/bin/mysqladmin
BACKUP_DIR=/mysql_backup #
FULLBACKUP_DIR=$BACKUP_DIR/full #
INCRBACKUP_DIR=$BACKUP_DIR/incre #
FULLBACKUP_INTERVAL=604800 # , :
KEEP_FULLBACKUP=5 #
logfiledate=backup.`date +%Y%m%d%H%M`.txt
LOGFILE_DIR=$BACKUP_DIR/logs
#
STARTED_TIME=`date +%s`
#############################################################################
#
#############################################################################
error()
{
echo "$1" 1>&2
exit 1
}
#
# -x file
if [ ! -x $INNOBACKUPEXFULL ]; then
error "$INNOBACKUPEXFULL /usr/bin."
fi
#-d file
if [ ! -d $BACKUP_DIR ]; then
error " :$BACKUP_DIR ."
fi
mysql_status=`netstat -nl | awk 'NR>2{if ($4 ~ /.*:3306/) {print "Yes";exit 0}}'`
if [ "$mysql_status" != "Yes" ];then
error "MySQL ."
fi
#
echo "----------------------------"
echo
echo "$0: MySQL "
echo " : `date +%F' '%T' '%w`"
echo
#
mkdir -p $FULLBACKUP_DIR
mkdir -p $INCRBACKUP_DIR
mkdir -p $LOGFILE_DIR
#
LATEST_FULL_BACKUP=`find $FULLBACKUP_DIR -mindepth 1 -maxdepth 1 -type d -printf "%P
" | sort -nr | head -1`
#
LATEST_FULL_BACKUP_CREATED_TIME=`stat -c %Y $FULLBACKUP_DIR/$LATEST_FULL_BACKUP`
#
##if -a -and
if [ "$LATEST_FULL_BACKUP" -a `expr $LATEST_FULL_BACKUP_CREATED_TIME + $FULLBACKUP_INTERVAL + 5` -ge $STARTED_TIME ] ; then
#
echo -e " $LATEST_FULL_BACKUP , $LATEST_FULL_BACKUP "
echo " "
NEW_INCRDIR=$INCRBACKUP_DIR/$LATEST_FULL_BACKUP
mkdir -p $NEW_INCRDIR
# .
LATEST_INCR_BACKUP=`find $NEW_INCRDIR -mindepth 1 -maxdepth 1 -type d -printf "%P
" | sort -nr | head -1`
if [ ! $LATEST_INCR_BACKUP ] ; then
INCRBASEDIR=$FULLBACKUP_DIR/$LATEST_FULL_BACKUP
echo -e " $INCRBASEDIR "
echo " "
else
INCRBASEDIR=$INCRBACKUP_DIR/${LATEST_FULL_BACKUP}/${LATEST_INCR_BACKUP}
echo -e " $INCRBASEDIR "
echo " "
fi
echo " $INCRBASEDIR ."
$INNOBACKUPEXFULL --defaults-file=$MY_CNF --incremental $NEW_INCRDIR --incremental-basedir $INCRBASEDIR > $TMPLOG 2>&1
#
cat $TMPLOG>$LOGFILE_DIR/$logfiledate
if [ -z "`tail -1 $TMPLOG | grep 'completed OK!'`" ] ; then
echo "$INNOBACKUPEX :"; echo
echo -e "---------- $INNOBACKUPEX_PATH ----------"
#cat $TMPLOG
rm -f $TMPLOG
exit 1
fi
THISBACKUP=`awk -- "/Backup created in directory/ { split( \\\$0, p, \"'\" ) ; print p[2] }" $TMPLOG`
rm -f $TMPLOG
echo -n " :$THISBACKUP"
echo
#
LATEST_FULL_BACKUP=`find $FULLBACKUP_DIR -mindepth 1 -maxdepth 1 -type d -printf "%P
" | sort -nr | head -1`
NEW_INCRDIR=$INCRBACKUP_DIR/$LATEST_FULL_BACKUP
LATEST_INCR_BACKUP=`find $NEW_INCRDIR -mindepth 1 -maxdepth 1 -type d -printf "%P
" | sort -nr | head -1`
RES_FULL_BACKUP=${FULLBACKUP_DIR}/${LATEST_FULL_BACKUP}
RES_INCRE_BACKUP=`dirname ${INCRBACKUP_DIR}/${LATEST_FULL_BACKUP}/${LATEST_INCR_BACKUP}`
echo
echo -e '\e[31m NOTE:---------------------------------------------------------------------------------.\e[m' #
echo -e " $KEEP_FULLBACKUP ${RES_FULL_BACKUP} ${RES_INCRE_BACKUP} ."
echo -e '\e[31m NOTE:---------------------------------------------------------------------------------.\e[m' #
echo
else
echo "*********************************"
echo -e " ... ..."
echo "*********************************"
$INNOBACKUPEXFULL --defaults-file=$MY_CNF --use-memory=4G $FULLBACKUP_DIR > $TMPLOG 2>&1
#
cat $TMPLOG>>$LOGFILE_DIR/$logfiledate
if [ -z "`tail -1 $TMPLOG | grep 'completed OK!'`" ] ; then
echo "$INNOBACKUPEX :"; echo
echo -e "---------- $INNOBACKUPEX_PATH ----------"
cat $TMPLOG
rm -f $TMPLOG
exit 1
fi
THISBACKUP=`awk -- "/Backup created in directory/ { split( \\\$0, p, \"'\" ) ; print p[2] }" $TMPLOG`
rm -f $TMPLOG
$INNOBACKUPEXFULL --apply-log $THISBACKUP > $TMPLOG 2>&1
cat $TMPLOG>>$LOGFILE_DIR/$logfiledate
echo -n " :$THISBACKUP"
echo
#
LATEST_FULL_BACKUP=`find $FULLBACKUP_DIR -mindepth 1 -maxdepth 1 -type d -printf "%P
" | sort -nr | head -1`
RES_FULL_BACKUP=${FULLBACKUP_DIR}/${LATEST_FULL_BACKUP}
echo
echo -e '\e[31m NOTE:---------------------------------------------------------------------------------.\e[m' #
echo -e " , $KEEP_FULLBACKUP ${RES_FULL_BACKUP}."
echo -e '\e[31m NOTE:---------------------------------------------------------------------------------.\e[m' #
echo
fi
#
echo -e "find expire backup file...........waiting........."
echo -e " ">>$LOGFILE_DIR/$logfiledate
for efile in $(/usr/bin/find $FULLBACKUP_DIR/ -mtime +7)
do
if [ -d ${efile} ]; then
echo -e " :${efile}" >>$BACKUP_DIR/$logfiledate
rm -rf "${efile}"
elif [ -f ${efile} ]; then
echo -e " :${efile}" >>$BACKUP_DIR/$logfiledate
rm -rf "${efile}"
fi;
done
if [ $? -eq "0" ];then
echo
echo -e " "
fi
#
echo -e "find expire backup file...........waiting........."
echo -e " ">>$LOGFILE_DIR/$logfiledate
for efile in $(/usr/bin/find $INCRBACKUP_DIR/ -mtime +8)
do
if [ -d ${efile} ]; then
echo -e " :${efile}" >>$BACKUP_DIR/$logfiledate
rm -rf "${efile}"
elif [ -f ${efile} ]; then
echo -e " :${efile}" >>$BACKUP_DIR/$logfiledate
rm -rf "${efile}"
fi;
done
if [ $? -eq "0" ];then
echo
echo -e " "
fi
echo
echo " : `date +%F' '%T' '%w`"
exit 0
2 사용자 이름 및 암호 포함
#!/bin/bash
#on xtrabackup 2.2.8
# ,
# ,
INNOBACKUPEX_PATH=innobackupex #INNOBACKUPEX
INNOBACKUPEXFULL=/usr/bin/$INNOBACKUPEX_PATH #INNOBACKUPEX
#mysql
MYSQL_CMD="--host=xxxxxx --user=root --password=xxxxx --port=3306"
TMPLOG="/tmp/innobackupex.$$.log"
MY_CNF=/etc/my.cnf #mysql
MYSQL=/usr/bin/mysql
MYSQL_ADMIN=/usr/bin/mysqladmin
BACKUP_DIR=/mysql_backup #
FULLBACKUP_DIR=$BACKUP_DIR/full #
INCRBACKUP_DIR=$BACKUP_DIR/incre #
FULLBACKUP_INTERVAL=604800 # , :
KEEP_FULLBACKUP=5 #
logfiledate=backup.`date +%Y%m%d%H%M`.txt
LOGFILE_DIR=$BACKUP_DIR/logs
#
STARTED_TIME=`date +%s`
#############################################################################
#
#############################################################################
error()
{
echo "$1" 1>&2
exit 1
}
#
# -x file
if [ ! -x $INNOBACKUPEXFULL ]; then
error "$INNOBACKUPEXFULL /usr/bin."
fi
#-d file
if [ ! -d $BACKUP_DIR ]; then
error " :$BACKUP_DIR ."
fi
mysql_status=`netstat -nl | awk 'NR>2{if ($4 ~ /.*:3306/) {print "Yes";exit 0}}'`
if [ "$mysql_status" != "Yes" ];then
error "MySQL ."
fi
#
echo "----------------------------"
echo
echo "$0: MySQL "
echo " : `date +%F' '%T' '%w`"
echo
#
mkdir -p $FULLBACKUP_DIR
mkdir -p $INCRBACKUP_DIR
mkdir -p $LOGFILE_DIR
#
LATEST_FULL_BACKUP=`find $FULLBACKUP_DIR -mindepth 1 -maxdepth 1 -type d -printf "%P
" | sort -nr | head -1`
#
LATEST_FULL_BACKUP_CREATED_TIME=`stat -c %Y $FULLBACKUP_DIR/$LATEST_FULL_BACKUP`
#
##if -a -and
if [ "$LATEST_FULL_BACKUP" -a `expr $LATEST_FULL_BACKUP_CREATED_TIME + $FULLBACKUP_INTERVAL + 5` -ge $STARTED_TIME ] ; then
#
echo -e " $LATEST_FULL_BACKUP , $LATEST_FULL_BACKUP "
echo " "
NEW_INCRDIR=$INCRBACKUP_DIR/$LATEST_FULL_BACKUP
mkdir -p $NEW_INCRDIR
# .
LATEST_INCR_BACKUP=`find $NEW_INCRDIR -mindepth 1 -maxdepth 1 -type d -printf "%P
" | sort -nr | head -1`
if [ ! $LATEST_INCR_BACKUP ] ; then
INCRBASEDIR=$FULLBACKUP_DIR/$LATEST_FULL_BACKUP
echo -e " $INCRBASEDIR "
echo " "
else
INCRBASEDIR=$INCRBACKUP_DIR/${LATEST_FULL_BACKUP}/${LATEST_INCR_BACKUP}
echo -e " $INCRBASEDIR "
echo " "
fi
echo " $INCRBASEDIR ."
$INNOBACKUPEXFULL --defaults-file=$MY_CNF --use-memory=4G $MYSQL_CMD --incremental $NEW_INCRDIR --incremental-basedir $INCRBASEDIR > $TMPLOG 2>&1
#
cat $TMPLOG>$LOGFILE_DIR/$logfiledate
if [ -z "`tail -1 $TMPLOG | grep 'completed OK!'`" ] ; then
echo "$INNOBACKUPEX :"; echo
echo -e "---------- $INNOBACKUPEX_PATH ----------"
#cat $TMPLOG
rm -f $TMPLOG
exit 1
fi
THISBACKUP=`awk -- "/Backup created in directory/ { split( \\\$0, p, \"'\" ) ; print p[2] }" $TMPLOG`
rm -f $TMPLOG
echo -n " :$THISBACKUP"
echo
#
LATEST_FULL_BACKUP=`find $FULLBACKUP_DIR -mindepth 1 -maxdepth 1 -type d -printf "%P
" | sort -nr | head -1`
NEW_INCRDIR=$INCRBACKUP_DIR/$LATEST_FULL_BACKUP
LATEST_INCR_BACKUP=`find $NEW_INCRDIR -mindepth 1 -maxdepth 1 -type d -printf "%P
" | sort -nr | head -1`
RES_FULL_BACKUP=${FULLBACKUP_DIR}/${LATEST_FULL_BACKUP}
RES_INCRE_BACKUP=`dirname ${INCRBACKUP_DIR}/${LATEST_FULL_BACKUP}/${LATEST_INCR_BACKUP}`
echo
echo -e '\e[31m NOTE:---------------------------------------------------------------------------------.\e[m' #
echo -e " $KEEP_FULLBACKUP ${RES_FULL_BACKUP} ${RES_INCRE_BACKUP} ."
echo -e '\e[31m NOTE:---------------------------------------------------------------------------------.\e[m' #
echo
else
echo "*********************************"
echo -e " ... ..."
echo "*********************************"
$INNOBACKUPEXFULL --defaults-file=$MY_CNF --use-memory=4G $MYSQL_CMD $FULLBACKUP_DIR > $TMPLOG 2>&1
#
cat $TMPLOG>>$LOGFILE_DIR/$logfiledate
if [ -z "`tail -1 $TMPLOG | grep 'completed OK!'`" ] ; then
echo "$INNOBACKUPEX :"; echo
echo -e "---------- $INNOBACKUPEX_PATH ----------"
cat $TMPLOG
rm -f $TMPLOG
exit 1
fi
THISBACKUP=`awk -- "/Backup created in directory/ { split( \\\$0, p, \"'\" ) ; print p[2] }" $TMPLOG`
rm -f $TMPLOG
$INNOBACKUPEXFULL --apply-log $THISBACKUP > $TMPLOG 2>&1
cat $TMPLOG>>$LOGFILE_DIR/$logfiledate
echo -n " :$THISBACKUP"
echo
#
LATEST_FULL_BACKUP=`find $FULLBACKUP_DIR -mindepth 1 -maxdepth 1 -type d -printf "%P
" | sort -nr | head -1`
RES_FULL_BACKUP=${FULLBACKUP_DIR}/${LATEST_FULL_BACKUP}
echo
echo -e '\e[31m NOTE:---------------------------------------------------------------------------------.\e[m' #
echo -e " , $KEEP_FULLBACKUP ${RES_FULL_BACKUP}."
echo -e '\e[31m NOTE:---------------------------------------------------------------------------------.\e[m' #
echo
fi
#
echo -e "find expire backup file...........waiting........."
echo -e " ">>$LOGFILE_DIR/$logfiledate
for efile in $(/usr/bin/find $FULLBACKUP_DIR/ -mtime +7)
do
if [ -d ${efile} ]; then
echo -e " :${efile}" >>$BACKUP_DIR/$logfiledate
rm -rf "${efile}"
elif [ -f ${efile} ]; then
echo -e " :${efile}" >>$BACKUP_DIR/$logfiledate
rm -rf "${efile}"
fi;
done
if [ $? -eq "0" ];then
echo
echo -e " "
fi
#
echo -e "find expire backup file...........waiting........."
echo -e " ">>$LOGFILE_DIR/$logfiledate
for efile in $(/usr/bin/find $INCRBACKUP_DIR/ -mtime +8)
do
if [ -d ${efile} ]; then
echo -e " :${efile}" >>$BACKUP_DIR/$logfiledate
rm -rf "${efile}"
elif [ -f ${efile} ]; then
echo -e " :${efile}" >>$BACKUP_DIR/$logfiledate
rm -rf "${efile}"
fi;
done
if [ $? -eq "0" ];then
echo
echo -e " "
fi
echo
echo " : `date +%F' '%T' '%w`"
exit 0
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.