From f3aeaa99a635da2a27d991100dc40f1659b99f0d Mon Sep 17 00:00:00 2001 From: uriwang Date: Tue, 22 Oct 2024 14:36:12 +0800 Subject: [PATCH] opt(dbbackup):add root directory check before deleting files --- .../src/backupexe/loader_physical_rocksdb.go | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/dbm-services/mysql/db-tools/mysql-dbbackup/pkg/src/backupexe/loader_physical_rocksdb.go b/dbm-services/mysql/db-tools/mysql-dbbackup/pkg/src/backupexe/loader_physical_rocksdb.go index 21377d6035..50504cb5a0 100644 --- a/dbm-services/mysql/db-tools/mysql-dbbackup/pkg/src/backupexe/loader_physical_rocksdb.go +++ b/dbm-services/mysql/db-tools/mysql-dbbackup/pkg/src/backupexe/loader_physical_rocksdb.go @@ -225,36 +225,43 @@ func (p *PhysicalRocksdbLoader) initConfig(indexContent *dbareport.IndexContent) line := scanner.Text() if strings.HasPrefix(line, "datadir=") { p.dataDir = strings.TrimPrefix(line, "datadir=") + p.dataDir = strings.TrimSpace(p.dataDir) continue } if strings.HasPrefix(line, "innodb_log_group_home_dir=") { p.innodbLogGroupHomeDir = strings.TrimPrefix(line, "innodb_log_group_home_dir=") + p.innodbLogGroupHomeDir = strings.TrimSpace(p.innodbLogGroupHomeDir) continue } if strings.HasPrefix(line, "innodb_data_home_dir=") { p.innodbDataHomeDir = strings.TrimPrefix(line, "innodb_data_home_dir=") + p.innodbDataHomeDir = strings.TrimSpace(p.innodbDataHomeDir) continue } if strings.HasPrefix(line, "log_bin=") { p.logbinDir = filepath.Dir(strings.TrimPrefix(line, "log_bin=")) + p.logbinDir = strings.TrimSpace(p.logbinDir) continue } if strings.HasPrefix(line, "relay-log=") { p.relaylogDir = filepath.Dir(strings.TrimPrefix(line, "relay-log=")) + p.relaylogDir = strings.TrimSpace(p.relaylogDir) continue } if strings.HasPrefix(line, "slow_query_log_file=") { p.slowQueryLogFile = filepath.Dir(strings.TrimPrefix(line, "slow_query_log_file=")) + p.slowQueryLogFile = strings.TrimSpace(p.slowQueryLogFile) continue } if strings.HasPrefix(line, "tmpdir=") { p.tmpDir = strings.TrimPrefix(line, "tmpdir=") + p.tmpDir = strings.TrimSpace(p.tmpDir) continue } } @@ -272,7 +279,7 @@ func (p *PhysicalRocksdbLoader) initConfig(indexContent *dbareport.IndexContent) func (p *PhysicalRocksdbLoader) cleanDirs() error { logger.Log.Infof("delete the data dir:%s", p.dataDir) - if p.dataDir != "" { + if p.dataDir != "" && p.dataDir != "/" { // delete the old directory os.RemoveAll(p.dataDir) // create the new directory @@ -280,7 +287,7 @@ func (p *PhysicalRocksdbLoader) cleanDirs() error { } logger.Log.Infof("delete the innodb log group home dir:%s", p.innodbLogGroupHomeDir) - if p.innodbDataHomeDir != "" { + if p.innodbLogGroupHomeDir != "" && p.innodbLogGroupHomeDir != "/" { // delete the old directory os.RemoveAll(p.innodbLogGroupHomeDir) // create the new directory @@ -288,7 +295,7 @@ func (p *PhysicalRocksdbLoader) cleanDirs() error { } logger.Log.Infof("delete the innodb data home dir:%s", p.innodbDataHomeDir) - if p.innodbDataHomeDir != "" { + if p.innodbDataHomeDir != "" && p.innodbDataHomeDir != "/" { // delete the old directory os.RemoveAll(p.innodbDataHomeDir) // create the new directory @@ -296,7 +303,7 @@ func (p *PhysicalRocksdbLoader) cleanDirs() error { } logger.Log.Infof("delete the relay log dir:%s", p.relaylogDir) - if p.relaylogDir != "" { + if p.relaylogDir != "" && p.relaylogDir != "/" { // delete the old directory os.RemoveAll(p.relaylogDir) // create the new directory @@ -304,7 +311,7 @@ func (p *PhysicalRocksdbLoader) cleanDirs() error { } logger.Log.Infof("delete the log bin dir:%s", p.logbinDir) - if p.logbinDir != "" { + if p.logbinDir != "" && p.logbinDir != "/" { // delete the old directory os.RemoveAll(p.logbinDir) // create the new directory @@ -312,7 +319,7 @@ func (p *PhysicalRocksdbLoader) cleanDirs() error { } logger.Log.Infof("delete the slow query log file:%s", p.slowQueryLogFile) - if p.slowQueryLogFile != "" { + if p.slowQueryLogFile != "" && p.slowQueryLogFile != "/" { // delete the old directory os.Remove(p.slowQueryLogFile) // create the new directory @@ -320,7 +327,7 @@ func (p *PhysicalRocksdbLoader) cleanDirs() error { } logger.Log.Infof("delete the tmp dir:%s", p.tmpDir) - if p.tmpDir != "" { + if p.tmpDir != "" && p.tmpDir != "/" { // delete the old directory os.RemoveAll(p.tmpDir) // create the new directory