Approaches to scripting a database backup using the MarkLogic ReST API
15 April 2020 04:31 AM
A question that customers frequently ask is for advice on managing backups outside the standard XQuery APIs or the web interface provided by MarkLogic.
This Knowledgebase article demonstrates two approaches to allow you to integrate the backup of a MarkLogic database into your dev-ops workflow by allowing such processes to be scripted or managed outside the product.
Creating a backup using the ReST API
You can use the ReST API to perform a database backup and to check on the status at any given time.
The examples listed below use XQuery to make the calls to the ReST API over http but you could similarly adapt the below examples to work with cURL - examples will also be given for this approach.
Here is an example that demonstrates a backup of the Documents database:
Running this should give you a job id as part of the response (in this example, we're using JSON to format the response but this can easily be changed by modifying the headers elements in the above sample to return application/xml instead):
Below is an example that demonstrates checking for the status of a given backup with the job-id given in the first step:
Example: using cURL (instead of XQuery)
Adapting the above examples so they work from cURL instead, you can generate a call that looks like this:
And to check on the status, the cURL payload could be modified to look like this: