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// DatabaseTarget is one declarative database backup target: the app name
53// is the identity, the service and database select the exact declaration
54// inside the app's ACTIVE record. Schedule is the declared backup
55// schedule of that database.
56type DatabaseTarget struct {
57 App string
58 Service string
59 Database string
60 Schedule BackupSchedule
61 ContainerID string
62}
63
64// BackupJob represents a scheduled or manual backup operation.
65type BackupJob struct {
66 ID string
67 // App is the canonical backup identity: an app name, never a domain.
68 App string
69 Service string
70 DBName string
71 Schedule BackupSchedule
72 Type BackupType
73 Status BackupJobStatus
74 StartedAt time.Time
75 CompletedAt time.Time
76 SizeBytes int64
77 FilePath string
78 Error string
79 Metadata map[string]string
80}
81
82// BackupResult is returned after a backup operation completes.
83type BackupResult struct {
84 Job BackupJob
85 Duration time.Duration
86}
87
88// DatabaseBackupJob represents a logical database backup operation.
89type DatabaseBackupJob = BackupJob
90
91// DatabaseBackupResult is returned after a database backup operation completes.
92type DatabaseBackupResult = BackupResult
93
94// RetentionPolicy defines how many backups to keep per schedule tier.
95type RetentionPolicy struct {
96 Hourly int
97 Daily int
98 Weekly int
99 Monthly int
100}
101
102// DatabaseBackupRetentionPolicy defines how many database backups to keep per schedule tier.
103type DatabaseBackupRetentionPolicy = RetentionPolicy
104
105// VolumeBackupRetentionPolicy defines how many volume backup archives to keep.
106type VolumeBackupRetentionPolicy struct {
107 Keep int
108}
109
110// BackupOverride allows per-domain backup configuration.
111type BackupOverride struct {
112 Schedules []BackupSchedule
113 Retention *RetentionPolicy
114}
115
116// BackupConfig is the database backup configuration.
117type BackupConfig struct {
118 Enabled bool
119 StorageDir string
120 Retention RetentionPolicy
121 Overrides map[string]BackupOverride
122}
123
124// DatabaseBackupConfig is the database backup configuration.
125type DatabaseBackupConfig = BackupConfig
126
127// VolumeBackupConfig is the volume backup configuration.
128type VolumeBackupConfig struct {
129 Enabled bool
130 Interval time.Duration
131 Compression VolumeBackupCompression
132 Retention VolumeBackupRetentionPolicy
133 Timeout time.Duration
134 MaxConcurrency int
135 HelperImage string
136 VolumePrefix string
137 S3Bucket string
138 S3Region string
139 S3Prefix string
140 S3Endpoint string
141 S3PathStyle bool
142 S3SSEAlgorithm string
143 S3SSEKMSKeyID string
144 // S3StorageClass is sent with every upload; empty keeps the bucket default.
145 S3StorageClass string
146}
147
148// VolumeBackupJob represents a filesystem archive backup of a named volume.
149type VolumeBackupJob struct {
150 ID string
151 // App is the canonical backup identity: an app name, never a domain.
152 App string
153 Service string
154 ContainerName string
155 ContainerID string
156 VolumeName string
157 RuntimeVolumeName string
158 MountPath string
159 Type BackupType
160 Status BackupJobStatus
161 StartedAt time.Time
162 CompletedAt time.Time
163 SizeBytes int64
164 ArtifactRef string
165 Error string
166 Metadata map[string]string
167}
168
169// VolumeBackupTarget identifies one declared volume backup source:
170// app, service, and the declared volume name. RuntimeVolumeName is the
171// runtime volume the archive is exported from, and MountPath is the
172// declared mount path inside that volume.
173type VolumeBackupTarget struct {
174 App string
175 Service string
176 VolumeName string
177 RuntimeVolumeName string
178 MountPath string
179}
180
181// VolumeArchiveRequest describes a volume archive export request.
182type VolumeArchiveRequest struct {
183 VolumeName string
184 MountPath string
185 Compression VolumeBackupCompression
186 HelperImage string
187}
188
189// VolumeArchiveMetadata contains metadata observed while exporting a volume archive.
190type VolumeArchiveMetadata struct {
191 SizeBytes int64
192 Checksum string
193}
194
195// VolumeArchiveResult contains a readable archive stream and export metadata.
196type VolumeArchiveResult struct {
197 Stream io.ReadCloser
198 Metadata VolumeArchiveMetadata
199}