diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/dbconsole_dump.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/dbconsole_dump.go index 7fc5ecadf8..840fcde298 100644 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/dbconsole_dump.go +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/dbconsole_dump.go @@ -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 } diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/util/mysqlutil/mysql_dumper.go b/dbm-services/mysql/db-tools/dbactuator/pkg/util/mysqlutil/mysql_dumper.go index 9fff605005..9c24b806d1 100644 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/util/mysqlutil/mysql_dumper.go +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/util/mysqlutil/mysql_dumper.go @@ -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 + `'` @@ -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", " ") }