增量式备份

This commit is contained in:
zhangkun9038@dingtalk.com 2023-07-15 21:23:48 +08:00
parent 7b36747e8c
commit 804406ed01

View File

@ -22,7 +22,7 @@ CURRENT_BINLOG=$(mysql -u$userName -p$password -h$host -N -e "SHOW MASTER STATUS
CURRENT_POSITION=$(mysql -u$userName -p$password -h$host -N -e "SHOW MASTER STATUS" | awk '{print $2}') CURRENT_POSITION=$(mysql -u$userName -p$password -h$host -N -e "SHOW MASTER STATUS" | awk '{print $2}')
if [[ -z "$LAST_BACKUP" ]]; then if [[ -z "$LAST_BACKUP" ]]; then
LAST_BINLOG=$CURRENT_BINLOG LAST_BINLOG="ON.000001"
LAST_POSITION="0" LAST_POSITION="0"
fi fi
echo "" echo ""
@ -35,8 +35,8 @@ cd $backUpPath
#if [ -z "$LAST_BINLOG" ]; then #if [ -z "$LAST_BINLOG" ]; then
# mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD -h $MYSQL_HOST $MYSQL_DATABASE > "$BACKUP_DIR/full_backup.sql" # mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD -h $MYSQL_HOST $MYSQL_DATABASE > "$BACKUP_DIR/full_backup.sql"
#else #else
echo "docker exec maria /usr/bin/mysqlbinlog -u"${userName}" -p"${password}" -h"${host}" --start-position="${LAST_BINLOG}" --stop-position="${CURRENT_POSITION}" "$LAST_BINLOG" > "${backUpPath}"/"${dbName}"-"${currentTime}".sql" echo "docker exec maria /usr/bin/mysqlbinlog -u"${userName}" -p"${password}" -h"${host}" --start-position="${LAST_POSITION}" --stop-position="${CURRENT_POSITION}" "$LAST_BINLOG" > "${backUpPath}"/"${dbName}"-"${currentTime}".sql"
docker exec maria /usr/bin/mysqlbinlog -u${userName} -p${password} -h${host} --start-position=${LAST_BINLOG} --stop-position=${CURRENT_POSITION} $LAST_BINLOG > ${backUpPath}/${dbName}-${currentTime}.sql docker exec maria /usr/bin/mysqlbinlog -u${userName} -p${password} -h${host} --start-position=${LAST_POSITION} --stop-position=${CURRENT_POSITION} $LAST_BINLOG > ${backUpPath}/${dbName}-${currentTime}.sql
#fi #fi
# 更新上次备份的binlog文件名和位置 # 更新上次备份的binlog文件名和位置
echo "$CURRENT_BINLOG $CURRENT_POSITION" > "last_backup.txt" echo "$CURRENT_BINLOG $CURRENT_POSITION" > "last_backup.txt"