增量式备份

This commit is contained in:
zhangkun9038@dingtalk.com 2023-07-14 22:54:51 +08:00
parent 6f42021a3c
commit 10145295eb

View File

@ -22,6 +22,7 @@ fi
echo ""
# 获取当前binlog文件名和位置
CURRENT_SBINLOG=$(mysql -u$userName -p$password -h$host -N -e "SHOW MASTER STATUS" | awk '{print $1}')
CURRENT_BINLOG=$(mysql -u$userName -p$password -h$host -N -e "SHOW MASTER STATUS" | awk '{print substr($1, 4)}')
CURRENT_POSITION=$(mysql -u$userName -p$password -h$host -N -e "SHOW MASTER STATUS" | awk '{print $2}')
@ -33,7 +34,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
echo "docker exec maria /usr/bin/mysqlbinlog -u"${userName}" -p"${password}" -h"${host}" --start-position="${LAST_BINLOG}" --stop-position="${CURRENT_POSITION}" > "${backUpPath}"/"${dbName}"-"${currentTime}".sql"
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"
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
#fi
# 更新上次备份的binlog文件名和位置