Restoring to the Safe Timestamp
If you want to restore as much data as possible, you can restore your data to the minimum safe timestamp.
For example, the database you want to restore has four forests, as shown below. You use the xdmp:host-status
function to locate the safe-restore-to-time
value, which is earliest of the four last-commit timestamps. In this example, the safe-restore-to-time
is the timestamp of the last committed transaction in Forest A.
The following procedure describes how to restore to the minimum timestamp using the XQuery API.
Note
This same procedure can be done using the Admin Interfaces described in Setting Merge Policy, Admin Interface for Database Restore, and Rolling Back a Transaction.
Use the
admin:database-get-merge-timestamp
function to get the current merge timestamp. Save this value so it can be reset after you have completed the rollback operation.Use the
admin:database-set-merge-timestamp
function to set the merge timestamp to any time before your minimum safe timestamp. This will preserve fragments in merge after this timestamp until you have rolled back your forest data.Use the
xdmp:database-restore
function with$journal-archiving
set tofn:true()
and$restoreToTime
set tonull( )
to restore the database to the latest timestamp.After the restore operation has completed, use the
xdmp:forest-rollback
function to roll back the forests to thesafe-restore-to-time
timestamp returned by thexdmp:host-status
function.For example, if you are restoring the Documents database, you can use the following query to rollback your forest data:
xquery version "1.0-ml"; declare namespace host = "http://marklogic.com/xdmp/status/host"; let $timestamp := xdmp:wallclock-to-timestamp( xs:dateTime(xdmp:host-status(xdmp:host("your-host.com")) /host:restore-jobs/host:restore-job/host:safe-restore-to-time /fn:data(.))) return xdmp:forest-rollback( xdmp:database-forests(xdmp:database("Documents")), $timestamp)
Use
admin:database-set-merge-timestamp
function to set the merge timestamp back to the value you saved in Step 1.