Browse Source

调整zip存放路径

master
xyiege 4 months ago
parent
commit
5d9b550276
  1. 3
      aufs/core/sendzip.go
  2. 16
      scagent/core/FileRpc.go
  3. 7
      scagent/main.go
  4. 4
      scagent/util/fsutil.go

3
aufs/core/sendzip.go

@ -70,6 +70,9 @@ func SendZip(w http.ResponseWriter, r *http.Request) {
RemoteAddr: remoteaddr[0],
RemotePath: remotepath[0],
}
fmt.Printf("zipblock:%v", zipblock)
// 从serip 切割出ip 和端口
splitip := strings.Split(serip[0], ":")
if len(splitip) != 2 {

16
scagent/core/FileRpc.go

@ -36,7 +36,7 @@ type ZipBlock struct {
Basepath string
Curpath string // 当前路径
SelFile []string // 选中的文件
RemoteAdr string // 远程主机地址,带端口
RemoteAddr string // 远程主机地址,带端口
RemotePath string // 远程主机的存储路径
}
@ -112,6 +112,7 @@ func (f *FileService) Upload(stream pb.FileUploadService_UploadFileServer, dirpa
// 压缩文件
// 返回压缩包的名称
func (f *FileService) Compress(args *ZipBlock, reply *string) error {
// fmt.Printf("compress args: %v\n", args)
// 启用日志
logger := util.NewProductionLogger()
defer logger.Sync()
@ -124,7 +125,7 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error {
taskId := make(chan string)
// 异步压缩
go func() {
util.CompressToZip(zpFileName, realFilePath, args.Basepath, args.SelFile)
util.CompressToZip(zpFileName, realFilePath, args.SelFile)
taskId <- "arcok"
// 日志输出
logger.Info("压缩文件", zap.String("filename", zpFileName), zap.String("path", realFilePath))
@ -137,12 +138,9 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error {
if strings.EqualFold(strings.ToLower(rest), "arcok") {
// 合并为实际路径
remotePath := path.Join("/www/wwwroot", args.RemotePath, zpFileName)
// 发送文件到远程服务器上
err := clientUploadFile(args.RemoteAdr, ziprl, remotePath)
if err != nil {
logger.Error("Compress", zap.String("msg", "上传文件到远程服务器失败"), zap.Error(err))
return nil
}
// 异步发送文件到远程服务器上
go clientUploadFile(args.RemoteAddr, ziprl, remotePath)
// 返回压缩包名称
*reply = ziprl
}
@ -155,7 +153,7 @@ const chunkSize = 1024 * 1024 // 1MB
// 客户端调用RPC传送文件的函数
// 传入zip的实际路径,远程的服务器带端口,远程文件存放路径
func clientUploadFile(remote string, filePath string, uploadPath string) error {
fmt.Printf("remote: %s, filePath: %s, uploadPath: %s\n", remote, filePath, uploadPath)
// 启用日志
logger := util.NewProductionLogger()
defer logger.Sync()

7
scagent/main.go

@ -47,6 +47,13 @@ func main() {
// 读取配置文件
util.ReadConfig()
// zip 存放位置
tgdir, err := os.Getwd()
if err != nil {
logger.Error("Getwd failed", zap.Error(err))
}
config.G.FilePath = tgdir
// 检查是否以守护进程方式运行
if isDaemon() {
// 以守护进程方式运行

4
scagent/util/fsutil.go

@ -310,7 +310,7 @@ func DecompressZip(zpFname string) error {
// dest:目的地址以及压缩文件名 eg:/data/logZip/2022-12-12-log.zip
// paths:需要压缩的所有文件所组成的集合
func CompressToZip(dest string, currentPath string, basepath string, paths []string) error {
func CompressToZip(dest string, currentPath string, paths []string) error {
// fmt.Printf("paths len:%d\n", len(paths))
// fmt.Println("real path", currentPath)
// 打开files 目录
@ -352,7 +352,7 @@ func CompressToZip(dest string, currentPath string, basepath string, paths []str
// 监听的工作目录作为文件的结尾,然后取相对路径
// 在zip存档中设置文件的相对路径
header.Name, err = filepath.Rel(filepath.Dir(basepath), path)
header.Name, err = filepath.Rel(filepath.Dir(config.G.FilePath), path)
if err != nil {
return err
}

Loading…
Cancel
Save