refactor: 移除SSH客户端相关代码,改用文件工具进行备份导出日志
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
|||||||
"be.ems/src/framework/cron"
|
"be.ems/src/framework/cron"
|
||||||
"be.ems/src/framework/database/redis"
|
"be.ems/src/framework/database/redis"
|
||||||
"be.ems/src/framework/logger"
|
"be.ems/src/framework/logger"
|
||||||
"be.ems/src/framework/ssh"
|
"be.ems/src/framework/utils/file"
|
||||||
neModel "be.ems/src/modules/ne/model"
|
neModel "be.ems/src/modules/ne/model"
|
||||||
neService "be.ems/src/modules/ne/service"
|
neService "be.ems/src/modules/ne/service"
|
||||||
neDataService "be.ems/src/modules/ne_data/service"
|
neDataService "be.ems/src/modules/ne_data/service"
|
||||||
@@ -56,33 +56,33 @@ func (s *BackupExportLogNEProcessor) Execute(data any) (any, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网元主机的SSH客户端
|
// // 网元主机的SSH客户端
|
||||||
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
|
// sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
result[neInfo.NeName] = err.Error()
|
// result[neInfo.NeName] = err.Error()
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
defer sshClient.Close()
|
// defer sshClient.Close()
|
||||||
// 网元主机的SSH客户端进行文件传输
|
// // 网元主机的SSH客户端进行文件传输
|
||||||
sftpClient, err := sshClient.NewClientSFTP()
|
// sftpClient, err := sshClient.NewClientSFTP()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
result[neInfo.NeName] = err.Error()
|
// result[neInfo.NeName] = err.Error()
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
defer sftpClient.Close()
|
// defer sftpClient.Close()
|
||||||
|
|
||||||
// 备份导出日志
|
// 备份导出日志
|
||||||
if neInfo.NeType == "IMS" {
|
if neInfo.NeType == "IMS" {
|
||||||
imsDirArr := [...]string{"icscf", "bgcf", "mmtel", "pcscf", "scscf", "iwf", "bsf", "ismc"}
|
imsDirArr := [...]string{"icscf", "bgcf", "mmtel", "pcscf", "scscf", "iwf", "bsf", "ismc"}
|
||||||
for _, dirPath := range imsDirArr {
|
for _, dirPath := range imsDirArr {
|
||||||
logFilePathIMS := filepath.ToSlash(filepath.Join(s.logFilePath, "ims", dirPath))
|
logFilePathIMS := filepath.ToSlash(filepath.Join(s.logFilePath, "ims", dirPath))
|
||||||
output := s.backup(timeDir, logFilePathIMS, neInfo, sshClient, sftpClient)
|
output := s.backup(timeDir, logFilePathIMS, neInfo)
|
||||||
for k, v := range output {
|
for k, v := range output {
|
||||||
result[k+"-"+dirPath] = v
|
result[k+"-"+dirPath] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
output := s.backup(timeDir, s.logFilePath, neInfo, sshClient, sftpClient)
|
output := s.backup(timeDir, s.logFilePath, neInfo)
|
||||||
for k, v := range output {
|
for k, v := range output {
|
||||||
result[k] = v
|
result[k] = v
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ func (s *BackupExportLogNEProcessor) Execute(data any) (any, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// backup 备份导出日志
|
// backup 备份导出日志
|
||||||
func (s *BackupExportLogNEProcessor) backup(timeDir string, logFilePath string, neInfo neModel.NeInfo, sshClient *ssh.ConnSSH, sftpClient *ssh.SSHClientSFTP) map[string]string {
|
func (s *BackupExportLogNEProcessor) backup(timeDir string, logFilePath string, neInfo neModel.NeInfo) map[string]string {
|
||||||
var result = map[string]string{}
|
var result = map[string]string{}
|
||||||
|
|
||||||
// 获取文件列表
|
// 获取文件列表
|
||||||
@@ -103,7 +103,7 @@ func (s *BackupExportLogNEProcessor) backup(timeDir string, logFilePath string,
|
|||||||
if neInfo.NeType == "IMS" {
|
if neInfo.NeType == "IMS" {
|
||||||
search = ""
|
search = ""
|
||||||
}
|
}
|
||||||
rows, err := ssh.FileList(sshClient, logFilePath, search)
|
rows, err := file.FileList(logFilePath, search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result[neInfo.NeName] = err.Error()
|
result[neInfo.NeName] = err.Error()
|
||||||
return result
|
return result
|
||||||
@@ -125,7 +125,7 @@ func (s *BackupExportLogNEProcessor) backup(timeDir string, logFilePath string,
|
|||||||
neDirPath = strings.Replace(neFilePath, s.logFilePath, "", 1)
|
neDirPath = strings.Replace(neFilePath, s.logFilePath, "", 1)
|
||||||
}
|
}
|
||||||
localFilePath := filepath.Join(s.backupService.BACKUP_DIR, "/log/ne_log", timeDir, neDirPath)
|
localFilePath := filepath.Join(s.backupService.BACKUP_DIR, "/log/ne_log", timeDir, neDirPath)
|
||||||
if err := sftpClient.CopyFileRemoteToLocal(neFilePath, localFilePath); err != nil {
|
if err := file.CopyFile(neFilePath, localFilePath); err != nil {
|
||||||
result[neInfo.NeName+"-copy"] = err.Error()
|
result[neInfo.NeName+"-copy"] = err.Error()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user