Using the below API I will get the list of all the snapshots but how will I get the snapshot id of the latest on-demand backup from that list?
curl -X GET -i --digest -u “{PUBLIC-KEY}:{PRIVATE-KEY}” “https://cloud.mongodb.com/api/atlas/v1.0/groups/6c7498dg87d9e6526801572b/clusters/Cluster0/snapshots ”
MaBeuLux88
(Maxime Beugnet)
June 13, 2022, 3:05pm
2
Hi @Vikas_Rathore ,
When you create the snapshot, you send a description
which is returned when you list the snapshots.
Would that work if you choose a specific pattern and then filter on it?
Cheers,
Maxime.
@MaBeuLux88 Thanks for helping.
Could you provide an example of how I can add a filter? Also, I might have multiple snapshots with the same description. can’t we do sorting according to the date it got created?
CODE=curl --user "${{ secrets.PUBLIC_KEY }}:${{ secrets.PRIVATE_KEY }}" \ --digest --include \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --request POST "https://cloud.mongodb.com/api/atlas/v1.0/groups/${{ secrets.PROJECT_ID }}/clusters/cluster-1/backup/snapshots?pretty=true" \ --data '{ "description" : "On Demand Snapshot", "retentionInDays" : 3 }'
MaBeuLux88
(Maxime Beugnet)
June 13, 2022, 4:36pm
4
Yes the date is provided. See the field created.date
.
You will have to implement the filter and the sort in your back-end code once the results are collected.
Supporting these options would make the API way more complex to support filtering and sorting on all the fields.
@MaBeuLux88 I am not using this in the backend code but I want to trigger it from a bash script in our CI/CD pipeline
MaBeuLux88
(Maxime Beugnet)
June 14, 2022, 6:35pm
6
Well it’s not the easiest language to process JSON but I think it’s doable. With some grep
, sort
, cut
and a few other magic commands I guess you can achieve this without too much trouble.