增量数据库备份服务

This commit is contained in:
zhangkun9038@dingtalk.com 2023-07-16 20:03:20 +08:00
parent 57fa14eabe
commit 36fa65fe50

View File

@ -7,6 +7,15 @@ host=$4
# 定义备份文件存放目录
backUpPath=$5
ossPath=$6
execPath=""
if [ -z "$7" ]; then
# 如果参数不存在,则使用默认值
execPath="docker exec maria /usr/bin/mysqlbinlog"
else
# 如果参数存在,则使用命令行参数的值
execPath="$7"
fi
# 获取上次备份的binlog文件名和位置
@ -36,7 +45,7 @@ cd $backUpPath
# 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_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_POSITION} --stop-position=${CURRENT_POSITION} /var/lib/mysql/$LAST_BINLOG > ${backUpPath}/${dbName}-incremental-${LAST_POSITION}-${CURRENT_POSITION}-${currentTime}.sql
$execPath -u${userName} -p${password} -h${host} --start-position=${LAST_POSITION} --stop-position=${CURRENT_POSITION} /var/lib/mysql/$LAST_BINLOG > ${backUpPath}/${dbName}-incremental-${LAST_POSITION}-${CURRENT_POSITION}-${currentTime}.sql
zip ${backUpPath}/${dbName}-incremental-${LAST_POSITION}-${CURRENT_POSITION}-${currentTime}.sql.zip ${backUpPath}/${dbName}-incremental-${LAST_POSITION}-${CURRENT_POSITION}-${currentTime}.sql
rm ${backUpPath}/${dbName}-incremental-${LAST_POSITION}-${CURRENT_POSITION}-${currentTime}.sql
ossutil cp ${dbName}-incremental-${LAST_POSITION}-${CURRENT_POSITION}-${currentTime}.sql.zip oss://$ossPath/$file