Skip to content

Commit 03ecb28

Browse files
authored
feat: add support to export snapshots on backup policies (#289)
1 parent 737750d commit 03ecb28

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

mongodbatlas/cloud_provider_snapshot_backup_policies.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ type CloudProviderSnapshotBackupPolicy struct {
5050
UpdateSnapshots *bool `json:"updateSnapshots,omitempty"` // Specify true to apply the retention changes in the updated backup policy to snapshots that Atlas took previously.
5151
NextSnapshot string `json:"nextSnapshot,omitempty"` // UTC ISO 8601 formatted point in time when Atlas will take the next snapshot.
5252
Policies []Policy `json:"policies,omitempty"` // A list of policy definitions for the cluster.
53+
AutoExportEnabled *bool `json:"autoExportEnabled,omitempty"` // Specify true to enable automatic export of cloud backup snapshots to the AWS bucket. You must also define the export policy using export. Specify false to disable automatic export.
54+
Export *Export `json:"export,omitempty"` // Export struct that represents a policy for automatically exporting cloud backup snapshots to AWS bucket.
5355
}
5456

5557
// Policy represents for the snapshot and an array of backup policy items.
@@ -67,6 +69,12 @@ type PolicyItem struct {
6769
RetentionValue int `json:"retentionValue,omitempty"` // Duration for which the backup is kept. Associated with retentionUnit.
6870
}
6971

72+
// Export represents a policy for automatically exporting cloud backup snapshots to AWS bucket.
73+
type Export struct {
74+
ExportBucketID string `json:"exportBucketId,omitempty"` // Unique identifier of the AWS bucket to export the cloud backup snapshot to.
75+
FrequencyType string `json:"frequencyType,omitempty"` // Frequency associated with the export policy.
76+
}
77+
7078
// Get gets the current snapshot schedule and retention settings for the cluster with {CLUSTER-NAME}.
7179
// See more: https://docs.atlas.mongodb.com/reference/api/cloud-provider-snapshot-schedule-get-all/
7280
func (s *CloudProviderSnapshotBackupPoliciesServiceOp) Get(ctx context.Context, groupID, clusterName string) (*CloudProviderSnapshotBackupPolicy, *Response, error) {

mongodbatlas/cloud_provider_snapshot_backup_policies_test.go

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ func TestCloudProviderSnapshotBackupPolicies_Get(t *testing.T) {
8686
],
8787
"referenceHourOfDay": 17,
8888
"referenceMinuteOfHour": 24,
89-
"restoreWindowDays": 7
89+
"restoreWindowDays": 7,
90+
"autoExportEnabled" : true,
91+
"export": {
92+
"frequencyType": "monthly",
93+
"exportBucketId": "604f6322dc786a5341d4f7fb"
94+
}
9095
}`)
9196
})
9297

@@ -137,6 +142,11 @@ func TestCloudProviderSnapshotBackupPolicies_Get(t *testing.T) {
137142
ReferenceHourOfDay: pointy.Int64(17),
138143
ReferenceMinuteOfHour: pointy.Int64(24),
139144
RestoreWindowDays: pointy.Int64(7),
145+
AutoExportEnabled: pointy.Bool(true),
146+
Export: &Export{
147+
ExportBucketID: "604f6322dc786a5341d4f7fb",
148+
FrequencyType: "monthly",
149+
},
140150
}
141151

142152
if diff := deep.Equal(snapshotBackupPolicy, expected); diff != nil {
@@ -178,7 +188,12 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) {
178188
},
179189
},
180190
},
181-
"updateSnapshots": true,
191+
"updateSnapshots": true,
192+
"autoExportEnabled": true,
193+
"export": map[string]interface{}{
194+
"frequencyType": "monthly",
195+
"exportBucketId": "604f6322dc786a5341d4f7fb",
196+
},
182197
}
183198

184199
var v map[string]interface{}
@@ -227,7 +242,12 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) {
227242
}
228243
],
229244
"referenceHourOfDay": 12,
230-
"referenceMinuteOfHour": 30
245+
"referenceMinuteOfHour": 30,
246+
"autoExportEnabled" : true,
247+
"export": {
248+
"frequencyType": "monthly",
249+
"exportBucketId": "604f6322dc786a5341d4f7fb"
250+
}
231251
}`)
232252
})
233253

@@ -255,7 +275,12 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) {
255275
},
256276
},
257277
},
258-
UpdateSnapshots: pointy.Bool(true),
278+
UpdateSnapshots: pointy.Bool(true),
279+
AutoExportEnabled: pointy.Bool(true),
280+
Export: &Export{
281+
ExportBucketID: "604f6322dc786a5341d4f7fb",
282+
FrequencyType: "monthly",
283+
},
259284
}
260285

261286
cloudProviderSnapshot, _, err := client.CloudProviderSnapshotBackupPolicies.Update(ctx, groupID, clusterName, updateRequest)
@@ -290,6 +315,11 @@ func TestCloudProviderSnapshotBackupPolicies_Update(t *testing.T) {
290315
},
291316
ReferenceHourOfDay: pointy.Int64(12),
292317
ReferenceMinuteOfHour: pointy.Int64(30),
318+
AutoExportEnabled: pointy.Bool(true),
319+
Export: &Export{
320+
ExportBucketID: "604f6322dc786a5341d4f7fb",
321+
FrequencyType: "monthly",
322+
},
293323
}
294324

295325
if diff := deep.Equal(cloudProviderSnapshot, expected); diff != nil {
@@ -331,7 +361,12 @@ func TestCloudProviderSnapshotBackupPolicies_Delete(t *testing.T) {
331361
],
332362
"referenceHourOfDay": 17,
333363
"referenceMinuteOfHour": 24,
334-
"restoreWindowDays": 7
364+
"restoreWindowDays": 7,
365+
"autoExportEnabled" : true,
366+
"export": {
367+
"frequencyType": "monthly",
368+
"exportBucketId": "604f6322dc786a5341d4f7fb"
369+
}
335370
}`)
336371
})
337372

@@ -353,6 +388,11 @@ func TestCloudProviderSnapshotBackupPolicies_Delete(t *testing.T) {
353388
ReferenceHourOfDay: pointy.Int64(17),
354389
ReferenceMinuteOfHour: pointy.Int64(24),
355390
RestoreWindowDays: pointy.Int64(7),
391+
AutoExportEnabled: pointy.Bool(true),
392+
Export: &Export{
393+
ExportBucketID: "604f6322dc786a5341d4f7fb",
394+
FrequencyType: "monthly",
395+
},
356396
}
357397

358398
if diff := deep.Equal(cloudProviderSnapshot, expected); diff != nil {

0 commit comments

Comments
 (0)