Skip to content

Commit

Permalink
opt(dbbackup):add root directory check before deleting files
Browse files Browse the repository at this point in the history
  • Loading branch information
ylgeeker committed Oct 22, 2024
1 parent 63b164c commit f3aeaa9
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -272,55 +279,55 @@ 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
os.MkdirAll(p.dataDir, 0755)
}

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
os.MkdirAll(p.innodbLogGroupHomeDir, 0755)
}

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
os.MkdirAll(p.innodbDataHomeDir, 0755)
}

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
os.MkdirAll(p.relaylogDir, 0755)
}

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
os.MkdirAll(p.logbinDir, 0755)
}

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
os.MkdirAll(p.slowQueryLogFile, 0755)
}

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
Expand Down

0 comments on commit f3aeaa9

Please sign in to comment.