From 0440f33cfb95dcb57270cadc99ae879b879e1546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Thu, 22 Jan 2026 03:13:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=87=E4=BB=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/backup.go | 18 +++++++++--- internal/data/cron.go | 18 ++++++------ internal/http/request/cron.go | 16 +++++------ internal/service/cli.go | 4 +-- web/src/views/task/CreateModal.vue | 46 ++++++++++++++++++++++++++---- 5 files changed, 74 insertions(+), 28 deletions(-) diff --git a/internal/data/backup.go b/internal/data/backup.go index e0d1f466..eba2146c 100644 --- a/internal/data/backup.go +++ b/internal/data/backup.go @@ -77,12 +77,22 @@ func (r *backupRepo) List(typ biz.BackupType) ([]*types.BackupFile, error) { // target 目标名称 // account 备份账号ID func (r *backupRepo) Create(ctx context.Context, typ biz.BackupType, target string, account uint) error { + // 取备份账号,0 为本地备份 backupAccount := new(biz.BackupAccount) - if err := r.db.First(backupAccount, account).Error; err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - return errors.New(r.t.Get("backup account not found")) + if account != 0 { + if err := r.db.First(backupAccount, account).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return errors.New(r.t.Get("backup account not found")) + } + return err + } + } else { + backupAccount = &biz.BackupAccount{ + Type: biz.BackupAccountTypeLocal, + Info: types.BackupAccountInfo{ + Path: r.GetDefaultPath(typ), + }, } - return err } client, err := r.getStorage(*backupAccount) diff --git a/internal/data/cron.go b/internal/data/cron.go index e6a39383..9b517b89 100644 --- a/internal/data/cron.go +++ b/internal/data/cron.go @@ -66,26 +66,26 @@ func (r *cronRepo) Create(ctx context.Context, req *request.CronCreate) error { script = fmt.Sprintf(`#!/bin/bash export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH -acepanel backup website -n '%s' -p '%s' -acepanel backup clear -t website -f '%s' -s '%d' -p '%s' -`, req.Target, req.BackupPath, req.Target, req.Save, req.BackupPath) +acepanel backup website -n '%s' -a '%d' +acepanel backup clear -t website -f '%s' -s '%d' -a '%d' +`, req.Target, req.BackupAccount, req.Target, req.Save, req.BackupAccount) } if req.BackupType == "mysql" || req.BackupType == "postgres" { script = fmt.Sprintf(`#!/bin/bash export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH -acepanel backup database -t '%s' -n '%s' -p '%s' -acepanel backup clear -t '%s' -f '%s' -s '%d' -p '%s' -`, req.BackupType, req.Target, req.BackupPath, req.BackupType, req.Target, req.Save, req.BackupPath) +acepanel backup database -t '%s' -n '%s' -a '%d' +acepanel backup clear -t '%s' -f '%s' -s '%d' -a '%d' +`, req.BackupType, req.Target, req.BackupAccount, req.BackupType, req.Target, req.Save, req.BackupAccount) } } if req.Type == "cutoff" { script = fmt.Sprintf(`#!/bin/bash export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH -acepanel cutoff website -n '%s' -p '%s' -acepanel cutoff clear -t website -n '%s' -s '%d' -p '%s' -`, req.Target, req.BackupPath, req.Target, req.Save, req.BackupPath) +acepanel cutoff website -n '%s' +acepanel cutoff clear -t website -n '%s' -s '%d' +`, req.Target, req.Target, req.Save) } if req.Type == "shell" { script = req.Script diff --git a/internal/http/request/cron.go b/internal/http/request/cron.go index 36e020ab..a9ba8335 100644 --- a/internal/http/request/cron.go +++ b/internal/http/request/cron.go @@ -1,14 +1,14 @@ package request type CronCreate struct { - Name string `form:"name" json:"name" validate:"required|notExists:crons,name"` - Type string `form:"type" json:"type" validate:"required"` - Time string `form:"time" json:"time" validate:"required|cron"` - Script string `form:"script" json:"script"` - BackupType string `form:"backup_type" json:"backup_type" validate:"requiredIf:Type,backup"` - BackupPath string `form:"backup_path" json:"backup_path"` - Target string `form:"target" json:"target" validate:"requiredIf:Type,backup,cutoff"` - Save int `form:"save" json:"save" validate:"required"` + Name string `form:"name" json:"name" validate:"required|notExists:crons,name"` + Type string `form:"type" json:"type" validate:"required"` + Time string `form:"time" json:"time" validate:"required|cron"` + Script string `form:"script" json:"script"` + BackupType string `form:"backup_type" json:"backup_type" validate:"requiredIf:Type,backup"` + BackupAccount uint `form:"backup_account" json:"backup_account"` + Target string `form:"target" json:"target" validate:"requiredIf:Type,backup,cutoff"` + Save int `form:"save" json:"save" validate:"required"` } type CronUpdate struct { diff --git a/internal/service/cli.go b/internal/service/cli.go index cf9052af..24a2b474 100644 --- a/internal/service/cli.go +++ b/internal/service/cli.go @@ -652,7 +652,6 @@ func (s *CliService) BackupPanel(ctx context.Context, cmd *cli.Command) error { } func (s *CliService) BackupClear(ctx context.Context, cmd *cli.Command) error { - path := s.backupRepo.GetDefaultPath(biz.BackupType(cmd.String("type"))) fmt.Println(s.hr) fmt.Println(s.t.Get("★ Start cleaning [%s]", time.Now().Format(time.DateTime))) @@ -661,11 +660,12 @@ func (s *CliService) BackupClear(ctx context.Context, cmd *cli.Command) error { fmt.Println(s.t.Get("|-Cleaning target: %s", cmd.String("file"))) fmt.Println(s.t.Get("|-Keep count: %d", cmd.Int("save"))) - if cmd.String("account") != "" { + if cmd.Uint("account") != 0 { if err := s.backupRepo.ClearAccountExpired(cmd.Uint("account"), biz.BackupType(cmd.String("type")), cmd.String("file"), cmd.Int("save")); err != nil { return errors.New(s.t.Get("Cleaning failed: %v", err)) } } else { + path := s.backupRepo.GetDefaultPath(biz.BackupType(cmd.String("type"))) if err := s.backupRepo.ClearExpired(path, cmd.String("file"), cmd.Int("save")); err != nil { return errors.New(s.t.Get("Cleaning failed: %v", err)) } diff --git a/web/src/views/task/CreateModal.vue b/web/src/views/task/CreateModal.vue index 3dd87765..dc1a8136 100644 --- a/web/src/views/task/CreateModal.vue +++ b/web/src/views/task/CreateModal.vue @@ -1,5 +1,6 @@ @@ -143,10 +178,11 @@ onMounted(() => { > - - +