Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: implement 2M limit to backup (#14454)

rebelice591f6392b0c2
diff --git a/backend/plugin/advisor/mysql/advisor_builtin_prior_backup_check.go b/backend/plugin/advisor/mysql/advisor_builtin_prior_backup_check.go
index 286819844a..b04ea7ef3f 100644
--- a/backend/plugin/advisor/mysql/advisor_builtin_prior_backup_check.go
+++ b/backend/plugin/advisor/mysql/advisor_builtin_prior_backup_check.go
@@ -9,6 +9,7 @@ import (
"github.com/antlr4-go/antlr/v4"
"github.com/pkg/errors"
+ "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/plugin/advisor"
mysqlparser "github.com/bytebase/bytebase/backend/plugin/parser/mysql"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -42,6 +43,18 @@ func (*StatementPriorBackupCheckAdvisor) Check(ctx advisor.Context, _ string) ([
}
title := string(ctx.Rule.Type)
+ if len(ctx.Statements) > common.MaxSheetCheckSize {
+ adviceList = append(adviceList, &storepb.Advice{
+ Status: level,
+ Title: title,
+ Content: fmt.Sprintf("The size of the SQL statements exceeds the maximum limit of %d bytes for backup", common.MaxSheetCheckSize),
+ Code: advisor.BuiltinPriorBackupCheck.Int32(),
+ StartPosition: &storepb.Position{
+ Line: 1,
+ },
+ })
+ }
+
for _, stmt := range stmtList {
checker := &mysqlparser.StatementTypeChecker{}
antlr.ParseTreeWalkerDefault.Walk(checker, stmt.Tree)
diff --git a/backend/runner/taskrun/data_update_executor.go b/backend/runner/taskrun/data_update_executor.go
index 6bd405315c..4a6c261ba6 100644
--- a/backend/runner/taskrun/data_update_executor.go
+++ b/backend/runner/taskrun/data_update_executor.go
@@ -219,6 +219,10 @@ func (exec *DataUpdateExecutor) backupData(
}
}
+ if len(statement) > common.MaxSheetCheckSize {
+ return nil, errors.Errorf("statement size %d exceeds the limit %d", len(statement), common.MaxSheetCheckSize)
+ }
+
prefix := "_" + time.Now().Format("20060102150405")
statements, err := base.TransformDMLToSelect(ctx, instance.Engine, tc, statement, database.DatabaseName, backupDatabaseName, prefix)
if err != nil {