增量式备份

This commit is contained in:
zhangkun9038@dingtalk.com 2023-07-14 17:31:04 +08:00
parent acc50f23f3
commit 83cb29d937

View File

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