auto_backup.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package model
  2. import (
  3. "strings"
  4. "time"
  5. )
  6. // BackupType represents the type of backup
  7. type BackupType string
  8. const (
  9. BackupTypeNginxAndNginxUI BackupType = "nginx_and_nginx_ui"
  10. BackupTypeCustomDir BackupType = "custom_dir"
  11. )
  12. // StorageType represents where the backup is stored
  13. type StorageType string
  14. const (
  15. StorageTypeLocal StorageType = "local"
  16. StorageTypeS3 StorageType = "s3"
  17. )
  18. // BackupStatus represents the status of the last backup
  19. type BackupStatus string
  20. const (
  21. BackupStatusPending BackupStatus = "pending"
  22. BackupStatusSuccess BackupStatus = "success"
  23. BackupStatusFailed BackupStatus = "failed"
  24. )
  25. // AutoBackup represents an automatic backup configuration
  26. type AutoBackup struct {
  27. Model
  28. Name string `json:"name" gorm:"not null;comment:Backup task name"`
  29. BackupType BackupType `json:"backup_type" gorm:"index;not null;comment:Type of backup"`
  30. StorageType StorageType `json:"storage_type" gorm:"index;not null;comment:Storage type (local/s3)"`
  31. BackupPath string `json:"backup_path" gorm:"comment:Custom directory path for backup"`
  32. StoragePath string `json:"storage_path" gorm:"not null;comment:Storage destination path"`
  33. CronExpression string `json:"cron_expression" gorm:"not null;comment:Cron expression for scheduling"`
  34. Enabled bool `json:"enabled" gorm:"index;default:true;comment:Whether the backup task is enabled"`
  35. LastBackupTime *time.Time `json:"last_backup_time" gorm:"comment:Last backup execution time"`
  36. LastBackupStatus BackupStatus `json:"last_backup_status" gorm:"default:'pending';comment:Status of last backup"`
  37. LastBackupError string `json:"last_backup_error" gorm:"comment:Error message from last backup if failed"`
  38. // S3 Configuration (only used when StorageType is S3)
  39. S3Endpoint string `json:"s3_endpoint" gorm:"comment:S3 endpoint URL"`
  40. S3AccessKeyID string `json:"s3_access_key_id" gorm:"comment:S3 access key ID;serializer:json[aes]"`
  41. S3SecretAccessKey string `json:"s3_secret_access_key" gorm:"comment:S3 secret access key;serializer:json[aes]"`
  42. S3Bucket string `json:"s3_bucket" gorm:"comment:S3 bucket name"`
  43. S3Region string `json:"s3_region" gorm:"comment:S3 region"`
  44. }
  45. func (a *AutoBackup) GetName() string {
  46. return strings.ReplaceAll(strings.TrimSpace(a.Name), " ", "_")
  47. }