Android / MongoDB Atlas / Modify Cloud Backup Backup Policy
Back to Collection Items
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
boolean success;
http.put_DigestAuth(true);
http.put_Login("username");
http.put_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
// }
CkJsonObject json = new CkJsonObject();
json.UpdateInt("referenceHourOfDay",12);
json.UpdateInt("referenceMinuteOfHour",30);
json.UpdateString("policies[0].id","5f8dc2299b9d310a7fde98e6");
json.UpdateString("policies[0].policyItems[0].id","5f8dc2299b9d310a7fde98e7");
json.UpdateString("policies[0].policyItems[0].frequencyType","hourly");
json.UpdateInt("policies[0].policyItems[0].frequencyInterval",6);
json.UpdateInt("policies[0].policyItems[0].retentionValue",2);
json.UpdateString("policies[0].policyItems[0].retentionUnit","days");
json.UpdateString("policies[0].policyItems[1].id","5f8dc2299b9d310a7fde98e9");
json.UpdateString("policies[0].policyItems[1].frequencyType","weekly");
json.UpdateInt("policies[0].policyItems[1].frequencyInterval",1);
json.UpdateInt("policies[0].policyItems[1].retentionValue",3);
json.UpdateString("policies[0].policyItems[1].retentionUnit","weeks");
json.UpdateBool("updateSnapshots",true);
CkStringBuilder sbRequestBody = new CkStringBuilder();
json.EmitSb(sbRequestBody);
CkHttpResponse resp = http.PTextSb("PATCH","https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/clusters/{{CLUSTER-NAME}}/backup/schedule",sbRequestBody,"utf-8","application/json",false,false);
if (http.get_LastMethodSuccess() == false) {
Log.i(TAG, http.lastErrorText());
return;
}
Log.i(TAG, String.valueOf(resp.get_StatusCode()));
Log.i(TAG, resp.bodyStr());
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}
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": [
]
}