auto_backup.go 2.3 KB

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