SQL Server / MongoDB Atlas / Modify Cloud Backup Backup Policy
Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OASetProperty @http, 'DigestAuth', 1
EXEC sp_OASetProperty @http, 'Login', 'username'
EXEC sp_OASetProperty @http, 'Password', 'password'
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "referenceHourOfDay": 12,
-- "referenceMinuteOfHour": 30,
-- "policies": [
-- {
-- "id": "5f8dc2299b9d310a7fde98e6",
-- "policyItems": [
-- {
-- "id": "5f8dc2299b9d310a7fde98e7",
-- "frequencyType": "hourly",
-- "frequencyInterval": 6,
-- "retentionValue": 2,
-- "retentionUnit": "days"
-- },
-- {
-- "id": "5f8dc2299b9d310a7fde98e9",
-- "frequencyType": "weekly",
-- "frequencyInterval": 1,
-- "retentionValue": 3,
-- "retentionUnit": "weeks"
-- }
-- ]
-- }
-- ],
-- "updateSnapshots": true
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'referenceHourOfDay', 12
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'referenceMinuteOfHour', 30
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'policies[0].id', '5f8dc2299b9d310a7fde98e6'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'policies[0].policyItems[0].id', '5f8dc2299b9d310a7fde98e7'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'policies[0].policyItems[0].frequencyType', 'hourly'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'policies[0].policyItems[0].frequencyInterval', 6
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'policies[0].policyItems[0].retentionValue', 2
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'policies[0].policyItems[0].retentionUnit', 'days'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'policies[0].policyItems[1].id', '5f8dc2299b9d310a7fde98e9'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'policies[0].policyItems[1].frequencyType', 'weekly'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'policies[0].policyItems[1].frequencyInterval', 1
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'policies[0].policyItems[1].retentionValue', 3
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'policies[0].policyItems[1].retentionUnit', 'weeks'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'updateSnapshots', 1
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PATCH', 'https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/backup/schedule', @sbRequestBody, 'utf-8', 'application/json', 0, 0
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
END
GO
Curl Command
curl -X PATCH
--digest -u 'username:password'
-d '{
"referenceHourOfDay": 12,
"referenceMinuteOfHour": 30,
"policies": [
{
"id": "5f8dc2299b9d310a7fde98e6",
"policyItems": [
{
"id": "5f8dc2299b9d310a7fde98e7",
"frequencyType": "hourly",
"frequencyInterval": 6,
"retentionValue": 2,
"retentionUnit": "days"
},
{
"id": "5f8dc2299b9d310a7fde98e9",
"frequencyType": "weekly",
"frequencyInterval": 1,
"retentionValue": 3,
"retentionUnit": "weeks"
}
]
}
],
"updateSnapshots": true
}'
https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/backup/schedule
Postman Collection Item JSON
{
"name": "Modify Cloud Backup Backup Policy",
"request": {
"method": "PATCH",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"referenceHourOfDay\": 12,\n \"referenceMinuteOfHour\": 30,\n \"policies\": [\n {\n \"id\": \"5f8dc2299b9d310a7fde98e6\",\n \"policyItems\": [\n {\n \"id\": \"5f8dc2299b9d310a7fde98e7\",\n \"frequencyType\": \"hourly\",\n \"frequencyInterval\": 6,\n \"retentionValue\": 2,\n \"retentionUnit\": \"days\"\n },\n {\n \"id\": \"5f8dc2299b9d310a7fde98e9\",\n \"frequencyType\": \"weekly\",\n \"frequencyInterval\": 1,\n \"retentionValue\": 3,\n \"retentionUnit\": \"weeks\"\n }\n ]\n }\n ],\n \"updateSnapshots\": true\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{base_url}}/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/backup/schedule",
"host": [
"{{base_url}}"
],
"path": [
"api",
"atlas",
"{{version}}",
"groups",
"{{ProjectID}}",
"clusters",
"{{CLUSTER-NAME}}",
"backup",
"schedule"
]
},
"description": "https://docs.atlas.mongodb.com/reference/api/cloud-backup/schedule/get-all-schedules/"
},
"response": [
]
}