mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2026-06-19 07:36:59 +00:00
fix(backup): change backup route from POST to GET and update name retrieval method in auto backup
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func InitRouter(r *gin.RouterGroup) {
|
||||
r.POST("/backup", CreateBackup)
|
||||
r.GET("/backup", CreateBackup)
|
||||
r.POST("/restore", RestoreBackup)
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ type BackupExecutionResult struct {
|
||||
// - error: CosyError if backup execution fails, nil if successful
|
||||
func ExecuteAutoBackup(autoBackup *model.AutoBackup) error {
|
||||
logger.Infof("Starting auto backup task: %s (ID: %d, Type: %s, Storage: %s)",
|
||||
autoBackup.Name, autoBackup.ID, autoBackup.BackupType, autoBackup.StorageType)
|
||||
autoBackup.GetName(), autoBackup.ID, autoBackup.BackupType, autoBackup.StorageType)
|
||||
|
||||
// Validate storage configuration before starting backup
|
||||
if err := validateStorageConfiguration(autoBackup); err != nil {
|
||||
@@ -158,7 +158,7 @@ func executeBackupByType(autoBackup *model.AutoBackup) (*BackupExecutionResult,
|
||||
// - error: CosyError if backup creation fails
|
||||
func createEncryptedBackup(autoBackup *model.AutoBackup, backupPrefix string) (*BackupExecutionResult, error) {
|
||||
// Generate unique filename with timestamp
|
||||
filename := fmt.Sprintf("%s_%s_%d.zip", backupPrefix, autoBackup.Name, time.Now().Unix())
|
||||
filename := fmt.Sprintf("%s_%s_%d.zip", backupPrefix, autoBackup.GetName(), time.Now().Unix())
|
||||
|
||||
// Determine output path based on storage type
|
||||
var outputPath string
|
||||
@@ -215,7 +215,7 @@ func createCustomDirectoryBackup(autoBackup *model.AutoBackup) (*BackupExecution
|
||||
}
|
||||
|
||||
// Generate unique filename with timestamp
|
||||
filename := fmt.Sprintf("custom_dir_%s_%d.zip", autoBackup.Name, time.Now().Unix())
|
||||
filename := fmt.Sprintf("custom_dir_%s_%d.zip", autoBackup.GetName(), time.Now().Unix())
|
||||
|
||||
// Determine output path based on storage type
|
||||
var outputPath string
|
||||
@@ -266,7 +266,7 @@ func writeBackupFile(filePath string, content []byte) error {
|
||||
// Returns:
|
||||
// - error: CosyError if key file writing fails
|
||||
func writeKeyFile(keyPath, aesKey, aesIv string) error {
|
||||
keyContent := fmt.Sprintf("AES_KEY=%s\nAES_IV=%s\n", aesKey, aesIv)
|
||||
keyContent := fmt.Sprintf("%s:%s", aesKey, aesIv)
|
||||
if err := os.WriteFile(keyPath, []byte(keyContent), 0600); err != nil {
|
||||
return cosy.WrapErrorWithParams(ErrAutoBackupWriteKeyFile, err.Error())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -52,3 +53,7 @@ type AutoBackup struct {
|
||||
S3Bucket string `json:"s3_bucket" gorm:"comment:S3 bucket name"`
|
||||
S3Region string `json:"s3_region" gorm:"comment:S3 region"`
|
||||
}
|
||||
|
||||
func (a *AutoBackup) GetName() string {
|
||||
return strings.ReplaceAll(a.Name, " ", "_")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user