- API >
- Public API Tutorials >
- Automate Backup Restoration through the API
Automate Backup Restoration through the API¶
On this page
Overview¶
Automating backup restorations involve manipulation of the automation
configuration. You first request a restore
link through the restoreJobs
resource and then add the restore link to the
automation configuration using the PUT
method.
You must add the restore link to each mongod instance in the
automation configuration’s processes
array. For example, for a sharded cluster
you add the restore link to each member process, including each config server.
To automate backup restoration, you must use PUT
. Do not use PATCH
.
Prerequisites¶
You must have access to the Public API. For more information, see Configure Public API Access.
Procedure¶
Retrieve the snapshot ID.¶
Use the snapshots resource to get the snapshot ID. Issue the following command, replacing:
<username>
,<apiKey>
with your API credentials,<url>
with the URL of Ops Manager,<group_id>
with the project ID from your Project Settings, and<cluster_id>
with the cluster ID.
Create a restore job for the snapshot.¶
Use the restoreJobs resource to request
an HTTP restore of the snapshot, which will provide a link to a downloadable
tar.gz
file. Issue the following command, replacing with your username, API
key, URL, project ID, and cluster ID as in the previous step. Replace
<snapshot_id>
with the snapshot ID you retrieved.
For an example, see Create One Restore Job.
Retrieve the restore link.¶
Use the restoreJobs resource to retrieve the restore link. Issue the following command, replacing with your username, API key, URL, project ID, and cluster ID as in the previous step.
Copy the restore link from the delivery.url
field.
Retrieve the automation configuration.¶
Use the automationConfig resource to retrieve the configuration. Issue the following command, replacing:
<username>
with your user name,<apiKey>
with your API credentials,<url>
with the URL of Ops Manager, and<group_id>
with the project ID from your Project Settings:
Confirm that the version
field of the retrieved automation
configuration matches the
version
field in the mms-cluster-config-backup.json file,
which is found on any server running the Automation Agent.
Add the restore link to the automation configuration.¶
In the processes
array, add the backupRestoreUrl
field to
each mongod (primary, secondary, and arbiter) to be
restored. Enter the restore link as the field’s value.
For example:
Send the updated automation configuration.¶
Use the automationConfig resource to send the updated automation configuration.
Issue the following command, replacing <configuration>
with path to the
updated configuration document. Replace the username, API key, URL, and
project ID as in previous steps.
Upon successful update of the configuration, the API returns the HTTP
200 OK
status code to indicate the request has succeeded.
Confirm successful update of the automation configuration.¶
Retrieve the automation configuration from Ops Manager and confirm it contains the changes. To retrieve the configuration, issue the following command, replacing username, API key, URL, and project ID as in previous steps.
Check the deployment status to ensure goal state is reached.¶
Use the automationStatus resource to retrieve the deployment status. Issue the following command, replacing username, API key, URL, and project ID as in previous steps.
Confirm that the values of all the lastGoalVersionAchieved
fields in the
processes
array match the goalVersion
field. For more information on
deployment status, see Automation Status.
Remove processes.backupRestoreUrl
.¶
When Goal State is achieved, remove the processes.backupRestoreUrl
field and resend the automation configuration.