Skip to content

Commit

Permalink
fix(dbm-services): console dump param position TencentBlueKing#8502
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq committed Dec 9, 2024
1 parent 65a59c7 commit 6b1a64c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,46 +246,31 @@ func (c *DbConsoleDumpComp) Run() (err error) {
}

if len(c.realTables) > 0 && len(c.dbs) > 1 {
err := fmt.Errorf("mysqldump only support one database if --tables not empty")
err = fmt.Errorf("mysqldump only support one database if --tables not empty")
logger.Error(err.Error())
return err
}

if len(c.realTables) > 0 {
dumper = mysqlutil.MySQLDumper{
DumpDir: c.backupDir,
Ip: c.Params.Host,
Port: c.Params.Port,
DbBackupUser: c.GeneralParam.RuntimeAccountParam.AdminUser,
DbBackupPwd: c.GeneralParam.RuntimeAccountParam.AdminPwd,
Tables: append(c.dbs, c.realTables...),
IgnoreTables: c.realIgnoreTables,
Where: c.Params.DumpDetail.Where,
DumpCmdFile: c.dumpCmd,
Charset: c.charset,
MySQLDumpOption: dumpOption,
}
} else {
dumper = mysqlutil.MySQLDumper{
DumpDir: c.backupDir,
Ip: c.Params.Host,
Port: c.Params.Port,
DbBackupUser: c.GeneralParam.RuntimeAccountParam.AdminUser,
DbBackupPwd: c.GeneralParam.RuntimeAccountParam.AdminPwd,
DbNames: c.dbs,
IgnoreTables: c.realIgnoreTables,
Where: c.Params.DumpDetail.Where,
DumpCmdFile: c.dumpCmd,
Charset: c.charset,
MySQLDumpOption: dumpOption,
}
dumper = mysqlutil.MySQLDumper{
DumpDir: c.backupDir,
Ip: c.Params.Host,
Port: c.Params.Port,
DbBackupUser: c.GeneralParam.RuntimeAccountParam.AdminUser,
DbBackupPwd: c.GeneralParam.RuntimeAccountParam.AdminPwd,
DbNames: c.dbs,
Tables: c.realTables,
IgnoreTables: c.realIgnoreTables,
Where: c.Params.DumpDetail.Where,
DumpCmdFile: c.dumpCmd,
Charset: c.charset,
MySQLDumpOption: dumpOption,
}

for _, db := range c.dbs {
backupfiles = append(backupfiles, fmt.Sprintf("%s.sql", db))
}

if err := dumper.Dump(); err != nil {
if err = dumper.Dump(); err != nil {
logger.Error("dump failed: %s", err.Error())
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,6 @@ func (m *MySQLDumper) getDumpCmd(outputFile, errFile, dumpOption string) (dumpCm
m.DbBackupPwd,
dumpOption,
)
if len(m.Tables) > 0 {
dumpCmd += fmt.Sprintf(" --tables %s", strings.Join(m.Tables, " "))
}

if len(m.IgnoreTables) > 0 {
for _, igTb := range m.IgnoreTables {
dumpCmd += fmt.Sprintf(" --ignore-table=%s", igTb)
}
}

if cmutil.IsNotEmpty(m.Where) {
dumpCmd += ` --where='` + m.Where + `'`
Expand All @@ -319,6 +310,17 @@ func (m *MySQLDumper) getDumpCmd(outputFile, errFile, dumpOption string) (dumpCm
dumpCmd += fmt.Sprintf(" --databases %s", strings.Join(m.DbNames, " "))
}
}

if len(m.Tables) > 0 {
dumpCmd += fmt.Sprintf(" --tables %s", strings.Join(m.Tables, " "))
}

if len(m.IgnoreTables) > 0 {
for _, igTb := range m.IgnoreTables {
dumpCmd += fmt.Sprintf(" --ignore-table=%s", igTb)
}
}

mysqlDumpCmd := fmt.Sprintf("%s > %s 2>%s", dumpCmd, outputFile, errFile)
return strings.ReplaceAll(mysqlDumpCmd, "\n", " ")
}
Expand Down

0 comments on commit 6b1a64c

Please sign in to comment.