|
@@ -8,7 +8,6 @@ import (
|
|
|
"cicv-data-closedloop/common/entity"
|
|
|
"cicv-data-closedloop/common/util"
|
|
|
"fmt"
|
|
|
- "io/fs"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
@@ -157,42 +156,52 @@ outLoop:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 额外采集data目录
|
|
|
- //err = util.ZipDir(commonConfig.CloudConfig.DataDir.Src, commonConfig.CloudConfig.DataDir.Dest, commonConfig.CloudConfig.DataDir.Exclude)
|
|
|
- //if err != nil {
|
|
|
- // c_log.GlobalLogger.Error("压缩data目录失败:", err)
|
|
|
- //}
|
|
|
- var filePaths []string // 初始化一个切片来保存文件路径
|
|
|
- err = filepath.WalkDir(commonConfig.CloudConfig.DataDir.Src, func(path string, d fs.DirEntry, err error) error { // 使用filepath.WalkDir遍历目录
|
|
|
+ // 压缩采集data目录
|
|
|
+ {
|
|
|
+ err = util.ZipDir(commonConfig.CloudConfig.DataDir.Src, commonConfig.CloudConfig.DataDir.Dest, commonConfig.CloudConfig.DataDir.Exclude)
|
|
|
if err != nil {
|
|
|
- return err // 如果有错误,返回错误
|
|
|
- }
|
|
|
-
|
|
|
- // 检查是否为文件(跳过目录)
|
|
|
- if !d.IsDir() {
|
|
|
- filePaths = append(filePaths, path) // 将文件路径添加到切片中
|
|
|
+ c_log.GlobalLogger.Error("压缩data目录失败:", err)
|
|
|
}
|
|
|
- return nil
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- c_log.GlobalLogger.Error("扫描 data 目录失败:", err)
|
|
|
- goto outLoop
|
|
|
- }
|
|
|
-
|
|
|
- // 不压缩上传所有文件
|
|
|
- for _, path := range filePaths {
|
|
|
- if strings.Contains(path, commonConfig.CloudConfig.DataDir.Exclude) {
|
|
|
- continue
|
|
|
- }
|
|
|
- relativePath := strings.Replace(path, commonConfig.CloudConfig.DataDir.Src, "", 1)
|
|
|
- ossKey := objectKey3 + "data/" + relativePath
|
|
|
- err = commonConfig.OssBucket.PutObjectFromFile(ossKey, path)
|
|
|
+ err = commonConfig.OssBucket.PutObjectFromFile(objectKey3+"data.zip", commonConfig.CloudConfig.DataDir.Dest)
|
|
|
if err != nil {
|
|
|
- c_log.GlobalLogger.Errorf("上传 data 目录内文件【%v】->【%v】失败:%v", path, ossKey, err)
|
|
|
- goto outLoop
|
|
|
+ c_log.GlobalLogger.Error("上传 data 目录压缩文件失败:", err)
|
|
|
}
|
|
|
+ commonConfig.OssMutex.Unlock()
|
|
|
+ }
|
|
|
+ // todo 不压缩采集data目录
|
|
|
+ {
|
|
|
+ //var filePaths []string // 初始化一个切片来保存文件路径
|
|
|
+ //err = filepath.WalkDir(commonConfig.CloudConfig.DataDir.Src, func(path string, d fs.DirEntry, err error) error { // 使用filepath.WalkDir遍历目录
|
|
|
+ // if err != nil {
|
|
|
+ // return err // 如果有错误,返回错误
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // 检查是否为文件(跳过目录)
|
|
|
+ // if !d.IsDir() {
|
|
|
+ // filePaths = append(filePaths, path) // 将文件路径添加到切片中
|
|
|
+ // }
|
|
|
+ // return nil
|
|
|
+ //})
|
|
|
+ //if err != nil {
|
|
|
+ // c_log.GlobalLogger.Error("扫描 data 目录失败:", err)
|
|
|
+ // goto outLoop
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //// 不压缩上传所有文件
|
|
|
+ //for _, path := range filePaths {
|
|
|
+ // if strings.Contains(path, commonConfig.CloudConfig.DataDir.Exclude) {
|
|
|
+ // continue
|
|
|
+ // }
|
|
|
+ // relativePath := strings.Replace(path, commonConfig.CloudConfig.DataDir.Src, "", 1)
|
|
|
+ // ossKey := objectKey3 + "data/" + relativePath
|
|
|
+ // err = commonConfig.OssBucket.PutObjectFromFile(ossKey, path)
|
|
|
+ // if err != nil {
|
|
|
+ // c_log.GlobalLogger.Errorf("上传 data 目录内文件【%v】->【%v】失败:%v", path, ossKey, err)
|
|
|
+ // goto outLoop
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //commonConfig.OssMutex.Unlock()
|
|
|
}
|
|
|
- commonConfig.OssMutex.Unlock()
|
|
|
|
|
|
// 删除本地所有已上传的bag文件
|
|
|
c_log.GlobalLogger.Infof("结束处理窗口,【Lable】=%v,【FaultTime】=%v,【Length】=%v", currentTimeWindow.Labels, currentTimeWindow.FaultTime, currentTimeWindow.Length)
|