增量式备份

This commit is contained in:
zhangkun9038@dingtalk.com 2023-07-14 17:26:50 +08:00
parent ffc46adc8b
commit 057bdbb930

6
backUpIncremental.sh Normal file → Executable file
View File

@ -15,8 +15,8 @@ LAST_BINLOG=$(echo "$LAST_BACKUP" | awk '{print $1}')
LAST_POSITION=$(echo "$LAST_BACKUP" | awk '{print $2}')
# 获取当前binlog文件名和位置
CURRENT_BINLOG=$(mysql -N -e "SHOW MASTER STATUS" | awk '{print $1}')
CURRENT_POSITION=$(mysql -N -e "SHOW MASTER STATUS" | awk '{print $2}')
CURRENT_BINLOG=$(mysql -u$userName -p$password -h$host -e "SHOW MASTER STATUS" | awk '{print $1}')
CURRENT_POSITION=$(mysql -u$userName -p$password -h$host -e "SHOW MASTER STATUS" | awk '{print $2}')
# 备份增量变更到文件
# 如果上次备份的binlog文件名和位置为空则进行全量备份
@ -24,7 +24,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
mysqlbinlog --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=$LAST_POSITION --stop-position=$CURRENT_POSITION --result-file="$backUpPath/$dbName-$currentTime.sql" $LAST_BINLOG
#fi
# 更新上次备份的binlog文件名和位置
echo "$CURRENT_BINLOG $CURRENT_POSITION" > "last_backup.txt"