From 63700763624c3d23e85cfcf64d944f2f18ec4150 Mon Sep 17 00:00:00 2001 From: simonzhangsz Date: Sat, 28 Oct 2023 16:23:54 +0800 Subject: [PATCH] add: rm expired backup file and shell script --- config/etc/default/restconf.yaml | 2 ++ makefile | 2 +- restagent/config/config.go | 2 ++ restagent/etc/restconf.yaml | 2 ++ .../delExpiredNeBackup/delExpiredNeBackup.go | 12 ++++++++++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/config/etc/default/restconf.yaml b/config/etc/default/restconf.yaml index e7166037..96fb7f41 100644 --- a/config/etc/default/restconf.yaml +++ b/config/etc/default/restconf.yaml @@ -93,6 +93,8 @@ omc: chk2ne: false sn: 13750650 checksign: false + rootDir: /usr/local/omc + binDir: /usr/local/omc/bin backup: /usr/local/omc/backup upload: /usr/local/omc/upload frontUpload: /usr/local/omc/htdocs/front/upload diff --git a/makefile b/makefile index aa57aa1c..7d5e130e 100644 --- a/makefile +++ b/makefile @@ -121,7 +121,7 @@ deb: $(BINNAME) chmod +x $(DebBuildDir)/usr/local/omc/bin/* #sed -i.bak 's/YYYYMMDD/$(shell date +"%Y%m%d")/g' $(DebBuildDir)/DEBIAN/control sed -i 's/YYYYMMDD/$(shell date +"%Y%m%d")/g' $(DebBuildDir)/DEBIAN/control - sed -i '73 s/user: root/user: agtuser/g' $(DebBuildDir)/usr/local/omc/etc/default/restconf.yaml + sed -i '74 s/user: root/user: agtuser/g' $(DebBuildDir)/usr/local/omc/etc/default/restconf.yaml dpkg -b $(DebBuildDir) $(ReleaseDebs)/$(DebPkgFile) rpm: $(BINNAME) diff --git a/restagent/config/config.go b/restagent/config/config.go index 6f9b3324..4df8dfc8 100644 --- a/restagent/config/config.go +++ b/restagent/config/config.go @@ -66,6 +66,8 @@ type YamlConfig struct { Chk2Ne bool `yaml:"chk2ne"` Sn string `yaml:"sn"` CheckSign bool `yaml:"checksign"` + RootDir string `yaml:"rootDir"` + BinDir string `yaml:"binDir"` Backup string `yaml:"backup"` Upload string `yaml:"upload"` FrontUpload string `yaml:"frontUpload"` diff --git a/restagent/etc/restconf.yaml b/restagent/etc/restconf.yaml index c91fe6ba..0ba13dc8 100644 --- a/restagent/etc/restconf.yaml +++ b/restagent/etc/restconf.yaml @@ -93,6 +93,8 @@ omc: chk2ne: false sn: 13750650 checksign: false + rootDir: ./ + binDir: ./bin backup: ./backup upload: ./upload frontUpload: d:/local.git/fe.ems/upload diff --git a/src/modules/crontask/delExpiredNeBackup/delExpiredNeBackup.go b/src/modules/crontask/delExpiredNeBackup/delExpiredNeBackup.go index 641641b9..85e9543d 100644 --- a/src/modules/crontask/delExpiredNeBackup/delExpiredNeBackup.go +++ b/src/modules/crontask/delExpiredNeBackup/delExpiredNeBackup.go @@ -5,7 +5,9 @@ import ( "fmt" "ems.agt/lib/dborm" + "ems.agt/lib/global" "ems.agt/lib/log" + "ems.agt/restagent/config" "ems.agt/src/framework/cron" ) @@ -71,7 +73,17 @@ func (s *BarProcessor) Execute(data any) (any, error) { // delete expired files in backup directory // todo ... + // command := fmt.Sprintf("find . -name '*.zip' -mtime +%d -type f -print | xargs rm -rf", duration) + command := fmt.Sprintf("%s/rmexpfiles.sh %s %d", config.GetYamlConfig().OMC.BinDir, config.GetYamlConfig().OMC.Backup, duration) + + log.Trace("command:", command) + out, err := global.ExecCmd(command) + if err != nil { + log.Error("Faile to exec command:", err) + return nil, err + } + log.Trace("command output:", out) // 返回结果,用于记录执行结果 return map[string]any{ "msg": "sucess",