From 23de99fe196928d2a447c7d85b77c1b0c70777d9 Mon Sep 17 00:00:00 2001 From: xfwduke Date: Thu, 12 Sep 2024 12:25:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(mysql):=20=E5=BA=93=E8=A1=A8=E5=A4=87?= =?UTF-8?q?=E4=BB=BDpayload=E6=B7=BB=E5=8A=A0=E8=BF=87=E6=BB=A4=E5=99=A8?= =?UTF-8?q?=E5=8F=82=E6=95=B0=20#6890?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mysql/backupdemand/backup_demand.go | 53 +++++++++++-------- .../flow/utils/mysql/mysql_act_playload.py | 5 +- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/backupdemand/backup_demand.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/backupdemand/backup_demand.go index 467e73eca1..7c1bf19336 100644 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/backupdemand/backup_demand.go +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/backupdemand/backup_demand.go @@ -10,6 +10,7 @@ package backupdemand import ( "bufio" + "dbm-services/mysql/db-tools/dbactuator/pkg/native" "encoding/json" "fmt" "math/rand" @@ -25,7 +26,6 @@ import ( "dbm-services/common/go-pubpkg/mysqlcomm" "dbm-services/mysql/db-tools/dbactuator/pkg/components" "dbm-services/mysql/db-tools/dbactuator/pkg/core/cst" - "dbm-services/mysql/db-tools/dbactuator/pkg/native" "dbm-services/mysql/db-tools/dbactuator/pkg/tools" "dbm-services/mysql/db-tools/dbactuator/pkg/util/db_table_filter" "dbm-services/mysql/db-tools/mysql-dbbackup/pkg/config" @@ -49,13 +49,15 @@ type Param struct { ShardID int `json:"shard_id"` BackupType string `json:"backup_type" validate:"required"` BackupGSD []string `json:"backup_gsd" validate:"required"` // [grant, schema, data] - // Regex database or tables to backup, only logical. set to empty if it's full backup // BackupFileTag file tag for backup system to file expires - BackupFileTag string `json:"backup_file_tag"` - Regex string `json:"regex"` - BackupId string `json:"backup_id" validate:"required"` - BillId string `json:"bill_id" validate:"required"` - CustomBackupDir string `json:"custom_backup_dir"` + BackupFileTag string `json:"backup_file_tag"` + BackupId string `json:"backup_id" validate:"required"` + BillId string `json:"bill_id" validate:"required"` + CustomBackupDir string `json:"custom_backup_dir"` + DbPatterns []string `json:"db_patterns"` + IgnoreDbs []string `json:"ignore_dbs"` + TablePatterns []string `json:"table_patterns"` + IgnoreTables []string `json:"ignore_tables"` } type context struct { @@ -147,17 +149,24 @@ func (c *Component) GenerateBackupConfig() error { backupConfig.LogicalBackup.Regex = "" if c.Params.BackupType == "logical" { - if c.Params.Regex == "" { - ignoreDbs := slices.DeleteFunc(native.DBSys, func(s string) bool { - return s == "infodba_schema" - }) - tf, _ := db_table_filter.NewFilter([]string{"*"}, []string{"*"}, ignoreDbs, nil) - myloaderRegex := tf.TableFilterRegex() - //myloaderRegex := tf.MyloaderRegex(true) ToDo xiaog 确认 - backupConfig.LogicalBackup.Regex = myloaderRegex - } else { - backupConfig.LogicalBackup.Regex = c.Params.Regex + ignoreDbs := slices.DeleteFunc(native.DBSys, func(s string) bool { + return s == "infodba_schema" + }) + ignoreDbs = append(ignoreDbs, c.Params.IgnoreDbs...) + backupConfig.LogicalBackup.Databases = strings.Join(c.Params.DbPatterns, ",") + backupConfig.LogicalBackup.ExcludeDatabases = strings.Join(ignoreDbs, ",") + backupConfig.LogicalBackup.Tables = strings.Join(c.Params.IgnoreTables, ",") + backupConfig.LogicalBackup.ExcludeTables = strings.Join(c.Params.IgnoreTables, ",") + + tf, err := db_table_filter.NewFilter( + c.Params.DbPatterns, c.Params.TablePatterns, + ignoreDbs, c.Params.IgnoreTables, + ) + if err != nil { + logger.Error("create table filter failed: %s", err.Error()) + return err } + backupConfig.LogicalBackup.Regex = tf.TableFilterRegex() } if c.Params.CustomBackupDir != "" { @@ -314,11 +323,11 @@ func (c *Component) OutPut() error { func (c *Component) Example() interface{} { return Component{ Params: &Param{ - Host: "x.x.x.x", - Port: 20000, - BackupType: "logical", - BackupGSD: []string{"grant", "schema", "data"}, - Regex: "", + Host: "x.x.x.x", + Port: 20000, + BackupType: "logical", + BackupGSD: []string{"grant", "schema", "data"}, + //Regex: "", BackupId: "uuid", BillId: "12234", CustomBackupDir: "backupDatabaseTable", diff --git a/dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py b/dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py index bc5cc5c9b1..e0f6c02636 100644 --- a/dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py +++ b/dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py @@ -1856,12 +1856,15 @@ def mysql_backup_demand_payload(self, **kwargs): "role": self.ticket_data["role"], "backup_type": self.ticket_data["backup_type"], "backup_gsd": self.ticket_data["backup_gsd"], - "regex": kwargs["trans_data"]["db_table_filter_regex"], "backup_id": self.ticket_data["backup_id"].__str__(), "bill_id": str(self.ticket_data["uid"]), "custom_backup_dir": self.ticket_data.get("custom_backup_dir", ""), "shard_id": self.ticket_data.get("shard_id", 0), "backup_file_tag": self.ticket_data.get("file_tag", ""), + "db_patterns": self.ticket_data.get("db_patterns", ""), + "ignore_dbs": self.ticket_data.get("ignore_dbs", ""), + "table_patterns": self.ticket_data.get("table_patterns", ""), + "ignore_tables": self.ticket_data.get("ignore_tables", ""), }, }, }