Skip to content

Commit

Permalink
fix(mysql): 库表备份payload添加过滤器参数 TencentBlueKing#6890
Browse files Browse the repository at this point in the history
  • Loading branch information
xfwduke committed Sep 12, 2024
1 parent 48c45a9 commit 23de99f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package backupdemand

import (
"bufio"
"dbm-services/mysql/db-tools/dbactuator/pkg/native"
"encoding/json"
"fmt"
"math/rand"
Expand All @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion dbm-ui/backend/flow/utils/mysql/mysql_act_playload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""),
},
},
}
Expand Down

0 comments on commit 23de99f

Please sign in to comment.