在这里插入代码片
//数据备份
控制器
func (s *UpdateRestore) HandleDiskList(c *gin.Context) (interface{}, error) {
return s.updaterestore.BackUp(c), nil
}
//数据备份
func (sn *UpdateRestore) BackUp(c *gin.Context) string {
ret, err := utils.ShellExec(". /etc/profile > dev/null; /etc/tos/scripts/sysconfig")
if err != nil {
return "false"
}
fileFullPath := fmt.Sprintf("%s%s", "/databack/", ret)
file, err := os.Open(fileFullPath)
defer file.Close()
fileName := path.Base(fileFullPath)
fileName = url.QueryEscape(fileName) // 防止中文乱码
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Transfer-Encoding", "binary")
c.Header("Cache-Control", "no-cache")
c.Header("Content-Disposition", "attachment;filename="+fileName+".zip")
return fileFullPath
}