2022-09-16 10:53:45 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2023-03-15 07:58:26 +00:00
|
|
|
"encoding/base64"
|
2023-05-12 14:30:26 +00:00
|
|
|
"fmt"
|
|
|
|
"path"
|
2023-03-15 07:58:26 +00:00
|
|
|
|
2022-10-17 08:32:31 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
2022-09-16 10:53:45 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Create backup account
|
|
|
|
// @Description 创建备份账号
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BackupOperate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /settings/backup [post]
|
2023-10-07 07:46:44 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"创建备份账号 [type]","formatEN":"create backup account [type]"}
|
2022-09-16 10:53:45 +00:00
|
|
|
func (b *BaseApi) CreateBackup(c *gin.Context) {
|
|
|
|
var req dto.BackupOperate
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-09-16 10:53:45 +00:00
|
|
|
return
|
|
|
|
}
|
2023-03-15 07:58:26 +00:00
|
|
|
if len(req.Credential) != 0 {
|
|
|
|
credential, err := base64.StdEncoding.DecodeString(req.Credential)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.Credential = string(credential)
|
|
|
|
}
|
|
|
|
if len(req.AccessKey) != 0 {
|
|
|
|
accessKey, err := base64.StdEncoding.DecodeString(req.AccessKey)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.AccessKey = string(accessKey)
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:53:45 +00:00
|
|
|
if err := backupService.Create(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2024-01-19 08:48:41 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Refresh OneDrive token
|
|
|
|
// @Description 刷新 OneDrive token
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /settings/backup/refresh/onedrive [post]
|
|
|
|
func (b *BaseApi) RefreshOneDriveToken(c *gin.Context) {
|
|
|
|
backupService.Run()
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary List buckets
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取 bucket 列表
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ForBuckets true "request"
|
2023-07-06 10:04:22 +00:00
|
|
|
// @Success 200 {array} string
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /settings/backup/search [post]
|
2022-09-16 10:53:45 +00:00
|
|
|
func (b *BaseApi) ListBuckets(c *gin.Context) {
|
|
|
|
var req dto.ForBuckets
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-09-16 10:53:45 +00:00
|
|
|
return
|
|
|
|
}
|
2023-03-15 07:58:26 +00:00
|
|
|
if len(req.Credential) != 0 {
|
|
|
|
credential, err := base64.StdEncoding.DecodeString(req.Credential)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.Credential = string(credential)
|
|
|
|
}
|
|
|
|
if len(req.AccessKey) != 0 {
|
|
|
|
accessKey, err := base64.StdEncoding.DecodeString(req.AccessKey)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.AccessKey = string(accessKey)
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:53:45 +00:00
|
|
|
buckets, err := backupService.GetBuckets(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, buckets)
|
|
|
|
}
|
|
|
|
|
2023-07-04 08:16:12 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Load OneDrive info
|
|
|
|
// @Description 获取 OneDrive 信息
|
|
|
|
// @Accept json
|
2024-01-19 15:06:41 +00:00
|
|
|
// @Success 200 {object} dto.OneDriveInfo
|
2023-07-04 08:16:12 +00:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /settings/backup/onedrive [get]
|
|
|
|
func (b *BaseApi) LoadOneDriveInfo(c *gin.Context) {
|
2024-01-19 15:06:41 +00:00
|
|
|
data, err := backupService.LoadOneDriveInfo()
|
2023-07-04 08:16:12 +00:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2024-01-19 15:06:41 +00:00
|
|
|
helper.SuccessWithData(c, data)
|
2023-07-04 08:16:12 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Delete backup account
|
|
|
|
// @Description 删除备份账号
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BatchDeleteReq true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /settings/backup/del [post]
|
2023-10-07 07:46:44 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":true,"db":"backup_accounts","output_column":"type","output_value":"types"}],"formatZH":"删除备份账号 [types]","formatEN":"delete backup account [types]"}
|
2022-09-16 10:53:45 +00:00
|
|
|
func (b *BaseApi) DeleteBackup(c *gin.Context) {
|
2023-04-17 08:06:28 +00:00
|
|
|
var req dto.OperateByID
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-09-16 10:53:45 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-17 08:06:28 +00:00
|
|
|
if err := backupService.Delete(req.ID); err != nil {
|
2022-09-16 10:53:45 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary Page backup records
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取备份记录列表分页
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.RecordSearch true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /settings/backup/record/search [post]
|
2022-11-29 09:39:10 +00:00
|
|
|
func (b *BaseApi) SearchBackupRecords(c *gin.Context) {
|
|
|
|
var req dto.RecordSearch
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-11-29 09:39:10 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
total, list, err := backupService.SearchRecordsWithPage(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Download backup record
|
|
|
|
// @Description 下载备份记录
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.DownloadRecord true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /settings/backup/record/download [post]
|
2023-10-07 07:46:44 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["source","fileName"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"下载备份记录 [source][fileName]","formatEN":"download backup records [source][fileName]"}
|
2022-10-28 03:02:47 +00:00
|
|
|
func (b *BaseApi) DownloadRecord(c *gin.Context) {
|
|
|
|
var req dto.DownloadRecord
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-10-28 03:02:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
filePath, err := backupService.DownloadRecord(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-03-18 02:03:40 +00:00
|
|
|
helper.SuccessWithData(c, filePath)
|
2022-10-28 03:02:47 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Delete backup record
|
|
|
|
// @Description 删除备份记录
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BatchDeleteReq true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /settings/backup/record/del [post]
|
2023-10-07 07:46:44 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"ids","isList":true,"db":"backup_records","output_column":"file_name","output_value":"files"}],"formatZH":"删除备份记录 [files]","formatEN":"delete backup records [files]"}
|
2022-10-27 15:09:39 +00:00
|
|
|
func (b *BaseApi) DeleteBackupRecord(c *gin.Context) {
|
|
|
|
var req dto.BatchDeleteReq
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-10-27 15:09:39 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := backupService.BatchDeleteRecord(req.Ids); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Update backup account
|
|
|
|
// @Description 更新备份账号信息
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BackupOperate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /settings/backup/update [post]
|
2023-10-07 07:46:44 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"更新备份账号 [types]","formatEN":"update backup account [types]"}
|
2022-09-16 10:53:45 +00:00
|
|
|
func (b *BaseApi) UpdateBackup(c *gin.Context) {
|
|
|
|
var req dto.BackupOperate
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2022-09-16 10:53:45 +00:00
|
|
|
return
|
|
|
|
}
|
2023-10-27 06:19:26 +00:00
|
|
|
|
2023-03-15 07:58:26 +00:00
|
|
|
if len(req.Credential) != 0 {
|
|
|
|
credential, err := base64.StdEncoding.DecodeString(req.Credential)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.Credential = string(credential)
|
|
|
|
}
|
|
|
|
if len(req.AccessKey) != 0 {
|
|
|
|
accessKey, err := base64.StdEncoding.DecodeString(req.AccessKey)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.AccessKey = string(accessKey)
|
|
|
|
}
|
|
|
|
|
2023-01-29 08:38:34 +00:00
|
|
|
if err := backupService.Update(req); err != nil {
|
2022-09-16 10:53:45 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary List backup accounts
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取备份账号列表
|
2023-07-06 10:04:22 +00:00
|
|
|
// @Success 200 {array} dto.BackupInfo
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /settings/backup/search [get]
|
2022-09-19 11:42:06 +00:00
|
|
|
func (b *BaseApi) ListBackup(c *gin.Context) {
|
|
|
|
data, err := backupService.List()
|
2022-09-16 10:53:45 +00:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-19 11:42:06 +00:00
|
|
|
helper.SuccessWithData(c, data)
|
2022-09-16 10:53:45 +00:00
|
|
|
}
|
2023-02-13 07:48:18 +00:00
|
|
|
|
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary List files from backup accounts
|
|
|
|
// @Description 获取备份账号内文件列表
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BackupSearchFile true "request"
|
2023-07-06 10:04:22 +00:00
|
|
|
// @Success 200 {array} string
|
2023-02-13 07:48:18 +00:00
|
|
|
// @Security ApiKeyAuth
|
2023-02-13 09:13:55 +00:00
|
|
|
// @Router /settings/backup/search/files [post]
|
2023-02-13 07:48:18 +00:00
|
|
|
func (b *BaseApi) LoadFilesFromBackup(c *gin.Context) {
|
|
|
|
var req dto.BackupSearchFile
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-02-13 07:48:18 +00:00
|
|
|
return
|
|
|
|
}
|
2023-10-27 06:19:26 +00:00
|
|
|
|
2023-02-13 07:48:18 +00:00
|
|
|
data, err := backupService.ListFiles(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, data)
|
|
|
|
}
|
2023-02-21 11:06:24 +00:00
|
|
|
|
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Backup system data
|
|
|
|
// @Description 备份系统数据
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.CommonBackup true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /settings/backup/ [post]
|
2023-10-07 07:46:44 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["type","name","detailName"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"备份 [type] 数据 [name][detailName]","formatEN":"backup [type] data [name][detailName]"}
|
2023-02-21 11:06:24 +00:00
|
|
|
func (b *BaseApi) Backup(c *gin.Context) {
|
|
|
|
var req dto.CommonBackup
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-02-21 11:06:24 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch req.Type {
|
|
|
|
case "app":
|
|
|
|
if err := backupService.AppBackup(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-08-29 02:50:15 +00:00
|
|
|
case "mysql", "mariadb":
|
2023-02-21 11:06:24 +00:00
|
|
|
if err := backupService.MysqlBackup(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-12-28 08:29:18 +00:00
|
|
|
case constant.AppPostgresql:
|
|
|
|
if err := backupService.PostgresqlBackup(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-02-21 11:06:24 +00:00
|
|
|
case "website":
|
|
|
|
if err := backupService.WebsiteBackup(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case "redis":
|
|
|
|
if err := backupService.RedisBackup(); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Recover system data
|
|
|
|
// @Description 恢复系统数据
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.CommonRecover true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /settings/backup/recover [post]
|
2023-10-07 07:46:44 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["type","name","detailName","file"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"从 [file] 恢复 [type] 数据 [name][detailName]","formatEN":"recover [type] data [name][detailName] from [file]"}
|
2023-02-21 11:06:24 +00:00
|
|
|
func (b *BaseApi) Recover(c *gin.Context) {
|
|
|
|
var req dto.CommonRecover
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-02-21 11:06:24 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-12 14:30:26 +00:00
|
|
|
if req.Source != "LOCAL" {
|
|
|
|
downloadPath, err := backupService.DownloadRecord(dto.DownloadRecord{Source: req.Source, FileDir: path.Dir(req.File), FileName: path.Base(req.File)})
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, fmt.Errorf("download file failed, err: %v", err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.File = downloadPath
|
|
|
|
}
|
2023-02-21 11:06:24 +00:00
|
|
|
switch req.Type {
|
2023-08-29 02:50:15 +00:00
|
|
|
case "mysql", "mariadb":
|
2023-02-21 11:06:24 +00:00
|
|
|
if err := backupService.MysqlRecover(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-12-28 08:29:18 +00:00
|
|
|
case constant.AppPostgresql:
|
|
|
|
if err := backupService.PostgresqlRecover(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-02-21 11:06:24 +00:00
|
|
|
case "website":
|
|
|
|
if err := backupService.WebsiteRecover(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-03-01 03:38:08 +00:00
|
|
|
case "redis":
|
|
|
|
if err := backupService.RedisRecover(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case "app":
|
|
|
|
if err := backupService.AppRecover(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-02-21 11:06:24 +00:00
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Recover system data by upload
|
|
|
|
// @Description 从上传恢复系统数据
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.CommonRecover true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /settings/backup/recover/byupload [post]
|
2023-10-07 07:46:44 +00:00
|
|
|
// @x-panel-log {"bodyKeys":["type","name","detailName","file"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"从 [file] 恢复 [type] 数据 [name][detailName]","formatEN":"recover [type] data [name][detailName] from [file]"}
|
2023-02-21 11:06:24 +00:00
|
|
|
func (b *BaseApi) RecoverByUpload(c *gin.Context) {
|
|
|
|
var req dto.CommonRecover
|
2023-10-27 06:19:26 +00:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
2023-02-21 11:06:24 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch req.Type {
|
2023-08-29 02:50:15 +00:00
|
|
|
case "mysql", "mariadb":
|
2023-02-21 11:06:24 +00:00
|
|
|
if err := backupService.MysqlRecoverByUpload(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-12-28 08:29:18 +00:00
|
|
|
case constant.AppPostgresql:
|
|
|
|
if err := backupService.PostgresqlRecoverByUpload(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-03-02 05:54:07 +00:00
|
|
|
case "app":
|
|
|
|
if err := backupService.AppRecover(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-02-21 11:06:24 +00:00
|
|
|
case "website":
|
|
|
|
if err := backupService.WebsiteRecover(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|