fix 任务周期备份配置文件发送ftp备份路径去掉一层
This commit is contained in:
@@ -30,7 +30,7 @@ func (s *NeConfigBackupProcessor) Execute(data any) (any, error) {
|
||||
s.count++ // 执行次数加一
|
||||
options := data.(cron.JobData)
|
||||
sysJob := options.SysJob
|
||||
logger.Infof("重复 %v 任务ID %s", options.Repeat, sysJob.JobID)
|
||||
logger.Infof("重复:%v 任务ID:%s 执行次数:%d", options.Repeat, sysJob.JobID, s.count)
|
||||
// 返回结果,用于记录执行结果
|
||||
result := map[string]any{
|
||||
"count": s.count,
|
||||
@@ -40,7 +40,7 @@ func (s *NeConfigBackupProcessor) Execute(data any) (any, error) {
|
||||
for _, neInfo := range neList {
|
||||
neTypeAndId := fmt.Sprintf("%s_%s", neInfo.NeType, neInfo.NeId)
|
||||
// 将网元文件备份到本地
|
||||
zipFilePath, err := s.neConfigBackupService.NeConfigNeToLocal(neInfo)
|
||||
zipFilePath, err := s.neConfigBackupService.FileNeToLocal(neInfo)
|
||||
if err != nil {
|
||||
result[neTypeAndId] = err.Error()
|
||||
continue
|
||||
@@ -62,7 +62,7 @@ func (s *NeConfigBackupProcessor) Execute(data any) (any, error) {
|
||||
|
||||
msg := "ok"
|
||||
// 上传到FTP服务器
|
||||
if err := s.backupService.FTPPushFile(zipFilePath, "ne_config"); err != nil {
|
||||
if err := s.backupService.FTPPushFile(zipFilePath, ""); err != nil {
|
||||
result[neTypeAndId] = msg + ", ftp err:" + err.Error()
|
||||
}
|
||||
result[neTypeAndId] = msg
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
@@ -129,27 +132,28 @@ func (s *NeConfigBackupController) Remove(c *gin.Context) {
|
||||
// 网元配置文件备份导入
|
||||
//
|
||||
// POST /import
|
||||
func (s *NeConfigBackupController) Import(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
func (s NeConfigBackupController) Import(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"`
|
||||
NeId string `json:"neId" binding:"required"`
|
||||
Type string `json:"type" binding:"required,oneof=backup upload"` // 导入类型
|
||||
Path string `json:"path" binding:"required"` // 文件路径
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
|
||||
return
|
||||
}
|
||||
if !strings.HasSuffix(body.Path, ".zip") {
|
||||
c.JSON(200, result.ErrMsg("Only supports decompression of zip files"))
|
||||
c.JSON(200, resp.ErrMsg("Only supports decompression of zip files"))
|
||||
return
|
||||
}
|
||||
|
||||
// 查网元
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
if neInfo.NeId != body.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
// 将zip文件解压到本地后复制到网元端
|
||||
@@ -157,36 +161,37 @@ func (s *NeConfigBackupController) Import(c *gin.Context) {
|
||||
if body.Type == "upload" {
|
||||
localFilePath = file.ParseUploadFilePath(body.Path)
|
||||
}
|
||||
if err := s.neConfigBackupService.NeConfigLocalToNe(neInfo, localFilePath); err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
if err := s.neConfigBackupService.FileLocalToNe(neInfo, localFilePath); err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 网元配置文件备份导出
|
||||
//
|
||||
// POST /export
|
||||
func (s *NeConfigBackupController) Export(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
func (s NeConfigBackupController) Export(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required"`
|
||||
NeId string `json:"neId" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
|
||||
return
|
||||
}
|
||||
// 查网元
|
||||
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
neInfo := s.neInfoService.FindByNeTypeAndNeID(body.NeType, body.NeId)
|
||||
if neInfo.NeId != body.NeId || neInfo.IP == "" {
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
|
||||
return
|
||||
}
|
||||
// 将网元文件备份到本地
|
||||
zipFilePath, err := s.neConfigBackupService.NeConfigNeToLocal(neInfo)
|
||||
zipFilePath, err := s.neConfigBackupService.FileNeToLocal(neInfo)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
// 新增备份记录
|
||||
@@ -195,7 +200,7 @@ func (s *NeConfigBackupController) Export(c *gin.Context) {
|
||||
NeId: neInfo.NeId,
|
||||
Name: filepath.Base(zipFilePath),
|
||||
Path: zipFilePath,
|
||||
CreateBy: ctx.LoginUserToUserName(c),
|
||||
CreateBy: reqctx.LoginUserToUserName(c),
|
||||
}
|
||||
s.neConfigBackupService.Insert(item)
|
||||
c.FileAttachment(item.Path, item.Name)
|
||||
|
||||
@@ -71,8 +71,8 @@ func (r *NeConfigBackup) DeleteByIds(ids []string) (int64, error) {
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// NeConfigLocalToNe 网元配置文件复制到网元端覆盖
|
||||
func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string) error {
|
||||
// FileLocalToNe 网元配置文件复制到网元端覆盖
|
||||
func (s NeConfigBackup) FileLocalToNe(neInfo model.NeInfo, localFile string) error {
|
||||
neTypeLower := strings.ToLower(neInfo.NeType)
|
||||
// 网管本地路径
|
||||
omcPath := "/usr/local/omc/backup/ne_config"
|
||||
@@ -106,7 +106,8 @@ func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string
|
||||
}
|
||||
|
||||
// 配置复制到网元内
|
||||
if neTypeLower == "ims" {
|
||||
switch neTypeLower {
|
||||
case "ims":
|
||||
// ims目录
|
||||
imsDirArr := [...]string{"bgcf", "icscf", "ismc", "mmtel", "mrf", "oam_manager.yaml", "pcscf", "scscf", "vars.cfg", "zlog"}
|
||||
for _, v := range imsDirArr {
|
||||
@@ -118,12 +119,10 @@ func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string
|
||||
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p /usr/local/etc/rtproxy && sudo cp -rf %s/rtproxy/* /usr/local/etc/rtproxy && sudo chmod 777 /usr/local/etc/rtproxy/rtproxy.conf", neDirTemp))
|
||||
// iwf目录
|
||||
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p /usr/local/etc/iwf && sudo cp -rf %s/iwf/* /usr/local/etc/iwf && sudo chmod 777 /usr/local/etc/iwf/*.yaml", neDirTemp))
|
||||
} else if neTypeLower == "omc" {
|
||||
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p /usr/local/omc/etc && sudo cp -rf %s/* /usr/local/omc/etc && sudo chmod 777 /usr/local/omc/etc/*.{yaml,conf}", neDirTemp))
|
||||
} else if neTypeLower == "smsc" {
|
||||
case "smsc":
|
||||
chmodFile := "sudo chmod 777 /usr/local/etc/smsc/{*sys.conf,*conf.txt,conf/is41_operation.conf}"
|
||||
sshClient.RunCMD(fmt.Sprintf("sudo mkdir -p /usr/local/etc/smsc/conf && sudo cp -rf %s/* /usr/local/etc/smsc && %s", neDirTemp, chmodFile))
|
||||
} else {
|
||||
default:
|
||||
neEtcPath := fmt.Sprintf("/usr/local/etc/%s", neTypeLower)
|
||||
chmodFile := fmt.Sprintf("sudo chmod 777 %s/*.yaml", neEtcPath)
|
||||
if neTypeLower == "mme" {
|
||||
@@ -137,8 +136,8 @@ func (r *NeConfigBackup) NeConfigLocalToNe(neInfo model.NeInfo, localFile string
|
||||
return nil
|
||||
}
|
||||
|
||||
// NeConfigNeToLocal 网元备份文件网元端复制到本地
|
||||
func (r *NeConfigBackup) NeConfigNeToLocal(neInfo model.NeInfo) (string, error) {
|
||||
// FileNeToLocal 网元备份文件网元端复制到本地
|
||||
func (s NeConfigBackup) FileNeToLocal(neInfo model.NeInfo) (string, error) {
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := NewNeInfo.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
|
||||
if err != nil {
|
||||
@@ -163,7 +162,8 @@ func (r *NeConfigBackup) NeConfigNeToLocal(neInfo model.NeInfo) (string, error)
|
||||
// 网元配置文件先复制到临时目录
|
||||
sshClient.RunCMD("sudo mkdir -p /tmp/omc/ne_config && sudo chmod 777 -R /tmp/omc")
|
||||
neDirTemp := fmt.Sprintf("/tmp/omc/ne_config/%s/%s", neTypeLower, neInfo.NeId)
|
||||
if neTypeLower == "ims" {
|
||||
switch neTypeLower {
|
||||
case "ims":
|
||||
// ims目录
|
||||
sshClient.RunCMD(fmt.Sprintf("mkdir -p %s/ims", neDirTemp))
|
||||
imsDirArr := [...]string{"bgcf", "icscf", "ismc", "mmtel", "mrf", "oam_manager.yaml", "pcscf", "scscf", "vars.cfg", "zlog"}
|
||||
@@ -176,12 +176,10 @@ func (r *NeConfigBackup) NeConfigNeToLocal(neInfo model.NeInfo) (string, error)
|
||||
sshClient.RunCMD(fmt.Sprintf("mkdir -p %s/rtproxy && sudo cp -rf /usr/local/etc/rtproxy/rtproxy.conf %s/rtproxy", neDirTemp, neDirTemp))
|
||||
// iwf目录
|
||||
sshClient.RunCMD(fmt.Sprintf("mkdir -p %s/iwf && sudo cp -rf /usr/local/etc/iwf/*.yaml %s/iwf", neDirTemp, neDirTemp))
|
||||
} else if neTypeLower == "omc" {
|
||||
sshClient.RunCMD(fmt.Sprintf("mkdir -p %s && sudo cp -rf /usr/local/omc/etc/*.{yaml,conf} %s", neDirTemp, neDirTemp))
|
||||
} else if neTypeLower == "smsc" {
|
||||
case "smsc":
|
||||
sshClient.RunCMD(fmt.Sprintf("mkdir -p %s && sudo cp -rf /usr/local/etc/smsc/{*.yaml,*.conf,*conf.txt} %s", neDirTemp, neDirTemp))
|
||||
sshClient.RunCMD(fmt.Sprintf("sudo cp -rf /usr/local/etc/smsc/conf %s/conf", neDirTemp))
|
||||
} else {
|
||||
default:
|
||||
nePath := fmt.Sprintf("/usr/local/etc/%s/*.yaml", neTypeLower)
|
||||
if neTypeLower == "mme" {
|
||||
nePath = fmt.Sprintf("/usr/local/etc/%s/*.{yaml,conf}", neTypeLower)
|
||||
|
||||
Reference in New Issue
Block a user