feat: 任务周期备份配置文件发送ftp备份
This commit is contained in:
@@ -331,7 +331,7 @@ func (s *FileController) File(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 检查路径是否在允许的目录范围内
|
||||
allowedPaths := []string{"/var/log", "/tmp", "/usr/local/omc/backup"}
|
||||
allowedPaths := []string{"/var/log", "/tmp", "/usr/local/omc/backup", "/usr/local/etc/omc"}
|
||||
allowed := false
|
||||
for _, p := range allowedPaths {
|
||||
if strings.HasPrefix(querys.Path, p) {
|
||||
@@ -382,7 +382,7 @@ func (s *FileController) Remove(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 检查路径是否在允许的目录范围内
|
||||
allowedPaths := []string{"/tmp", "/usr/local/omc/backup"}
|
||||
allowedPaths := []string{"/tmp", "/usr/local/omc/backup", "/usr/local/etc/omc"}
|
||||
allowed := false
|
||||
for _, p := range allowedPaths {
|
||||
if strings.HasPrefix(querys.Path, p) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"be.ems/src/framework/cron"
|
||||
"be.ems/src/framework/logger"
|
||||
neDataService "be.ems/src/modules/network_data/service"
|
||||
neModel "be.ems/src/modules/network_element/model"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
)
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
var NewProcessor = &NeConfigBackupProcessor{
|
||||
neConfigBackupService: neService.NewNeConfigBackup,
|
||||
neInfoService: neService.NewNeInfo,
|
||||
backupService: neDataService.NewBackup,
|
||||
count: 0,
|
||||
}
|
||||
|
||||
@@ -20,6 +22,7 @@ var NewProcessor = &NeConfigBackupProcessor{
|
||||
type NeConfigBackupProcessor struct {
|
||||
neConfigBackupService *neService.NeConfigBackup // 网元配置文件备份记录服务
|
||||
neInfoService *neService.NeInfo // 网元信息服务
|
||||
backupService *neDataService.Backup // 备份相关服务
|
||||
count int // 执行次数
|
||||
}
|
||||
|
||||
@@ -42,6 +45,7 @@ func (s *NeConfigBackupProcessor) Execute(data any) (any, error) {
|
||||
result[neTypeAndId] = err.Error()
|
||||
continue
|
||||
}
|
||||
|
||||
// 新增备份记录
|
||||
item := neModel.NeConfigBackup{
|
||||
NeType: neInfo.NeType,
|
||||
@@ -50,8 +54,18 @@ func (s *NeConfigBackupProcessor) Execute(data any) (any, error) {
|
||||
Path: zipFilePath,
|
||||
CreateBy: "system",
|
||||
}
|
||||
s.neConfigBackupService.Insert(item)
|
||||
result[neTypeAndId] = "ok"
|
||||
rows := s.neConfigBackupService.Insert(item)
|
||||
if rows == "" {
|
||||
result[neTypeAndId] = "failed"
|
||||
continue
|
||||
}
|
||||
|
||||
msg := "ok"
|
||||
// 上传到FTP服务器
|
||||
if err := s.backupService.FTPPushFile(zipFilePath, "ne_config"); err != nil {
|
||||
result[neTypeAndId] = msg + ", ftp err:" + err.Error()
|
||||
}
|
||||
result[neTypeAndId] = msg
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
Reference in New Issue
Block a user