diff --git a/scagent/core/FileRpc.go b/scagent/core/FileRpc.go index cc54fc7..4f56c7e 100644 --- a/scagent/core/FileRpc.go +++ b/scagent/core/FileRpc.go @@ -61,8 +61,10 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error { // 日志输出 logger.Info("压缩文件", zap.String("filename", zpFileName), zap.String("path", realFilePath)) }() + // 年月格式的目录 + dirpath := fmt.Sprintf("%d/%02d", time.Now().Year(), time.Now().Month()) // ZIP 文件的实际路径 - ziprl := path.Join(config.G.FilePath, "/sync_zips", zpFileName) + ziprl := path.Join(config.G.FilePath, "/sync_zips", dirpath, zpFileName) // zip 创建成功后 rest := <-taskId // 如果压缩包生成成功以后再执行 diff --git a/scagent/util/fsutil.go b/scagent/util/fsutil.go index 646e863..5ae444b 100644 --- a/scagent/util/fsutil.go +++ b/scagent/util/fsutil.go @@ -335,7 +335,7 @@ func CompressToZip(dest string, currentPath string, paths []string) error { fmt.Println(err.Error()) } // ToSlash 过滤windows的斜杠引起的bug - zfile, err := os.Create(path.Join(filesPath, dest)) + zfile, err := os.Create(path.Join("./sync_zips", "/", dest)) if err != nil { return err } @@ -409,7 +409,8 @@ func CompressToZip(dest string, currentPath string, paths []string) error { } } // 存到指定位置 - os.Rename(dest, path.Join("./sync_zips/", dest)) + // os.Rename(dest, path.Join("./sync_zips/", dest)) + os.Rename(path.Join("./sync_zips/", dest), path.Join(filesPath, dest)) return nil }