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