backup.go RawHistoryFolder
1package domain
2
3import "time"
4
5// DBType identifies the database engine.
6type DBType string
7
8const (
9 DBTypePostgreSQL DBType = "postgresql"
10 DBTypeUnknown DBType = "unknown"
11)
12
13// BackupSchedule defines when backups run.
14type BackupSchedule string
15
16const (
17 ScheduleHourly BackupSchedule = "hourly"
18 ScheduleDaily BackupSchedule = "daily"
19 ScheduleWeekly BackupSchedule = "weekly"
20 ScheduleMonthly BackupSchedule = "monthly"
21)
22
23// BackupType distinguishes backup methods.
24type BackupType string
25
26const (
27 BackupTypeLogical BackupType = "logical"
28)
29
30// BackupJobStatus tracks backup job lifecycle state.
31type BackupJobStatus string
32
33const (
34 BackupStatusPending BackupJobStatus = "pending"
35 BackupStatusRunning BackupJobStatus = "running"
36 BackupStatusCompleted BackupJobStatus = "completed"
37 BackupStatusFailed BackupJobStatus = "failed"
38)
39
40// DBInfo holds detected database information from an attachment container.
41type DBInfo struct {
42 Type DBType
43 Version string
44 Domain string
45 Name string
46 Host string
47 Port int
48 ContainerID string
49 ImageName string
50 // Credentials contains sensitive values (passwords/tokens).
51 // Never log or expose this map in API responses.
52 Credentials map[string]string `json:"-"`
53}
54
55// ClearCredentials clears sensitive credential values from DBInfo.
56func (d *DBInfo) ClearCredentials() {
57 if d == nil || d.Credentials == nil {
58 return
59 }
60 for k := range d.Credentials {
61 d.Credentials[k] = ""
62 delete(d.Credentials, k)
63 }
64 d.Credentials = nil
65}
66
67// BackupJob represents a scheduled or manual backup operation.
68type BackupJob struct {
69 ID string
70 Domain string
71 DBName string
72 Schedule BackupSchedule
73 Type BackupType
74 Status BackupJobStatus
75 StartedAt time.Time
76 CompletedAt time.Time
77 SizeBytes int64
78 FilePath string
79 Error string
80 Metadata map[string]string
81}
82
83// BackupResult is returned after a backup operation completes.
84type BackupResult struct {
85 Job BackupJob
86 Duration time.Duration
87}
88
89// RetentionPolicy defines how many backups to keep per schedule tier.
90type RetentionPolicy struct {
91 Hourly int
92 Daily int
93 Weekly int
94 Monthly int
95}
96
97// BackupOverride allows per-domain backup configuration.
98type BackupOverride struct {
99 Schedules []BackupSchedule
100 Retention *RetentionPolicy
101}
102
103// BackupConfig is the top-level backup configuration.
104type BackupConfig struct {
105 Enabled bool
106 StorageDir string
107 Retention RetentionPolicy
108 Overrides map[string]BackupOverride
109}
110
111// Backup labels for container metadata.
112const (
113 LabelBackupEnabled = "gordon.backup"
114 LabelBackupType = "gordon.backup.type"
115 LabelBackupVersion = "gordon.backup.version"
116 LabelBackupSchedule = "gordon.backup.schedule"
117 LabelBackupSidecar = "gordon.backup.sidecar"
118)