auto_backup.go 2.4 KB

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