backup.go RawHistoryFolder
1package domain
2
3import (
4 "io"
5 "time"
6)
7
8// DBType identifies the database engine.
9type DBType string
10
11const (
12 DBTypePostgreSQL DBType = "postgresql"
13 DBTypeUnknown DBType = "unknown"
14)
15
16// BackupSchedule defines when backups run.
17type BackupSchedule string
18
19const (
20 ScheduleHourly BackupSchedule = "hourly"
21 ScheduleDaily BackupSchedule = "daily"
22 ScheduleWeekly BackupSchedule = "weekly"
23 ScheduleMonthly BackupSchedule = "monthly"
24)
25
26// BackupType distinguishes backup methods.
27type BackupType string
28
29const (
30 BackupTypeLogical BackupType = "logical"
31 BackupTypeVolumeArchive BackupType = "volume_archive"
32)
33
34// VolumeBackupCompression identifies the archive compression format for volume backups.
35type VolumeBackupCompression string
36
37const (
38 VolumeBackupCompressionGzip VolumeBackupCompression = "gzip"
39 VolumeBackupCompressionZstd VolumeBackupCompression = "zstd"
40)
41
42// BackupJobStatus tracks backup job lifecycle state.
43type BackupJobStatus string
44
45const (
46 BackupStatusPending BackupJobStatus = "pending"
47 BackupStatusRunning BackupJobStatus = "running"
48 BackupStatusCompleted BackupJobStatus = "completed"
49 BackupStatusFailed BackupJobStatus = "failed"
50)
51
52// DBInfo holds detected database information from an attachment container.
53type DBInfo struct {
54 Type DBType
55 Version string
56 Domain string
57 Name string
58 Host string
59 Port int
60 ContainerID string
61 ImageName string
62 // Credentials contains sensitive values (passwords/tokens).
63 // Never log or expose this map in API responses.
64 Credentials map[string]string `json:"-"`
65}
66
67// ClearCredentials clears sensitive credential values from DBInfo.
68func (d *DBInfo) ClearCredentials() {
69 if d == nil || d.Credentials == nil {
70 return
71 }
72 for k := range d.Credentials {
73 d.Credentials[k] = ""
74 delete(d.Credentials, k)
75 }
76 d.Credentials = nil
77}
78
79// BackupJob represents a scheduled or manual backup operation.
80type BackupJob struct {
81 ID string
82 Domain string
83 DBName string
84 Schedule BackupSchedule
85 Type BackupType
86 Status BackupJobStatus
87 StartedAt time.Time
88 CompletedAt time.Time
89 SizeBytes int64
90 FilePath string
91 Error string
92 Metadata map[string]string
93}
94
95// BackupResult is returned after a backup operation completes.
96type BackupResult struct {
97 Job BackupJob
98 Duration time.Duration
99}
100
101// DatabaseBackupJob represents a logical database backup operation.
102type DatabaseBackupJob = BackupJob
103
104// DatabaseBackupResult is returned after a database backup operation completes.
105type DatabaseBackupResult = BackupResult
106
107// RetentionPolicy defines how many backups to keep per schedule tier.
108type RetentionPolicy struct {
109 Hourly int
110 Daily int
111 Weekly int
112 Monthly int
113}
114
115// DatabaseBackupRetentionPolicy defines how many database backups to keep per schedule tier.
116type DatabaseBackupRetentionPolicy = RetentionPolicy
117
118// VolumeBackupRetentionPolicy defines how many volume backup archives to keep.
119type VolumeBackupRetentionPolicy struct {
120 Keep int
121}
122
123// BackupOverride allows per-domain backup configuration.
124type BackupOverride struct {
125 Schedules []BackupSchedule
126 Retention *RetentionPolicy
127}
128
129// BackupConfig is the database backup configuration.
130type BackupConfig struct {
131 Enabled bool
132 StorageDir string
133 Retention RetentionPolicy
134 Overrides map[string]BackupOverride
135}
136
137// DatabaseBackupConfig is the database backup configuration.
138type DatabaseBackupConfig = BackupConfig
139
140// VolumeBackupConfig is the volume backup configuration.
141type VolumeBackupConfig struct {
142 Enabled bool
143 Interval time.Duration
144 Compression VolumeBackupCompression
145 Retention VolumeBackupRetentionPolicy
146 Timeout time.Duration
147 MaxConcurrency int
148 HelperImage string
149 VolumePrefix string
150 S3Bucket string
151 S3Region string
152 S3Prefix string
153 S3Endpoint string
154 S3PathStyle bool
155 S3SSEAlgorithm string
156 S3SSEKMSKeyID string
157}
158
159// VolumeBackupJob represents a filesystem archive backup of a named volume.
160type VolumeBackupJob struct {
161 ID string
162 Domain string
163 ContainerName string
164 ContainerID string
165 VolumeName string
166 MountPath string
167 Type BackupType
168 Status BackupJobStatus
169 StartedAt time.Time
170 CompletedAt time.Time
171 SizeBytes int64
172 ArtifactRef string
173 Error string
174 Metadata map[string]string
175}
176
177// VolumeBackupTarget identifies one selected volume backup source.
178type VolumeBackupTarget struct {
179 Domain string
180 ContainerName string
181 ContainerID string
182 VolumeName string
183 MountPath string
184}
185
186// VolumeArchiveRequest describes a volume archive export request.
187type VolumeArchiveRequest struct {
188 VolumeName string
189 MountPath string
190 Compression VolumeBackupCompression
191 HelperImage string
192}
193
194// VolumeArchiveMetadata contains metadata observed while exporting a volume archive.
195type VolumeArchiveMetadata struct {
196 SizeBytes int64
197 Checksum string
198}
199
200// VolumeArchiveResult contains a readable archive stream and export metadata.
201type VolumeArchiveResult struct {
202 Stream io.ReadCloser
203 Metadata VolumeArchiveMetadata
204}
205
206// Backup labels for container metadata.
207const (
208 LabelBackupEnabled = "gordon.backup"
209 LabelBackupType = "gordon.backup.type"
210 LabelBackupVersion = "gordon.backup.version"
211 LabelBackupSchedule = "gordon.backup.schedule"
212 LabelBackupSidecar = "gordon.backup.sidecar"
213)