feat: 添加系统备份功能,权限控制分配
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"be.ems/src/modules/network_data/model"
|
||||
"be.ems/src/modules/network_data/service"
|
||||
|
||||
@@ -99,3 +100,42 @@ func (s BackupController) FTPPush(c *gin.Context) {
|
||||
}
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 备份文件-导入OMC
|
||||
//
|
||||
// POST /import-omc
|
||||
func (s BackupController) ImportOMC(c *gin.Context) {
|
||||
var body struct {
|
||||
NeType string `json:"neType" binding:"required,oneof=OMC"`
|
||||
Path string `json:"path" binding:"required"` // 文件路径
|
||||
}
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
|
||||
return
|
||||
}
|
||||
if !strings.HasSuffix(body.Path, ".zip") {
|
||||
c.JSON(200, resp.ErrMsg("Only supports decompression of zip files"))
|
||||
return
|
||||
}
|
||||
|
||||
// 将zip文件解压到本地后复制到网元端
|
||||
localFilePath := file.ParseUploadFilePath(body.Path)
|
||||
if err := s.backupService.BackupOMCImport(localFilePath); err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 备份文件-导出OMC
|
||||
//
|
||||
// POST /export-omc
|
||||
func (s BackupController) ExportOMC(c *gin.Context) {
|
||||
zipFilePath, err := s.backupService.BackupOMCExport()
|
||||
if err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.FileAttachment(zipFilePath, filepath.Base(zipFilePath))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user