In 9.0 Zerto added support for additional API’s for backup and recovery operations.
Manual Retention API
The backup API allows users to initiate a manual retention job which includes the ability to select a tagged checkpoint as source, configure the expiration and set the type of backup (full or incremental).
VM restore from Long-term Retention API
The restore API allows users to recover a VM from Long-term Retention, define the target datastore and host as parameters.
How to use the API’s
Zerto’s REST APIs provide a way to automate many of the tasks required to manage DR, without having to use the Zerto User Interface.
For further information on the API’s available please see the documentation on myZerto.
Adding a session
Using the username and password either for the Windows machine where the Zerto Virtual Manager is installed or for the hypervisor manager, VMware vCenter Server or Microsoft SCVMM, accessed by the Zerto Virtual Manager, you can establish a session by posting the following URL: https://zerto_ip:port/v1/session/add
A session identifier, x-zerto-session, is returned as part of the response header and the session is established. The session identifier is used in the client code with every API call for the duration of the session.
You can see all the available API’s by using the Get command and https://zerto_ip:port/v1/
To get a list of existing VPG’s with LTR enabled we want to use the Get command with https://zerto_ip:port/v1/ltr/catalog/vms
Using the VPG identifier from the previous command we can now list the checkpoints that we can use for the manual retention. To list the available checkpoints for a VPG use the Get command with https://zerto_ip:port/v1/vpgs/<protectionGroupIdentifier>/checkpoints
Alternatively you can add a new checkpoint and use a tagged checkpoint for the manual retention. To add a new checkpoint use the Post command with https://zerto_ip:port/v1/vpgs/<protectionGroupIdentifier>/Checkpoints with the body “CheckpointName”: “Tag Name”
We can now see the tagged checkpoint from the below list using the Get command with https://zerto_ip:port/v1/vpgs/<protectionGroupIdentifier>/checkpoints
Now we have the VPG identifier and the checkpoint ID or tag we can start a manual retention operation. To start the retention use the Post command with https://zerto_ip:port/v1/ltr/vpgs/<protectionGroupIdentidfier>/retentionstart with the body of “CheckpointIdentifer”:”CheckpointID’ or “Tag”: “Tag Name”
You can check the Zerto UI or since we are focusing on API’s in this blog you can check the event logs to see if the retention was successful using the Get command with https://zerto_ip:port/v1/events
To restore a VM using the API we need to add a session again following the steps above. To get a list of VM’s with LTR enabled use the Get command with https://zerto_ip:port/v1/ltr/catalog/vms
Using the VM identifier you can now list the available retention sets you can use for recovery. To list all retention sets for your VM use the Get command with https://zerto_ip:port/v1/catalog/vms/<vmIdentifier>/retentionsets
Now we have the VM identifier and retention set information for recovery let’s look at getting the information to restore the VM to a particular host and datastore. To get the host identifier use the Get command with https://zerto_ip:port/v1/virtualizationsites/<SiteId>/hosts (if you need the site id you can use the Get command with https://zerto_ip:port/v1/virtualizationsites).
You can see from the above I have 2 hosts to choose from, now I need to get my datastore ID where I want to restore the VM to. To list the available datastores use the Get command with https://zerto_ip:port/v1/datastores.
We now have all the information required to perform the restore operation. To initiate the restore use the Post command with https://zerto_ip:port/v1/ltr/restore/vm with the body “LTRVmIdentifier” : “vmIdentifier”, ‘RetentionSetIdentifier” : “RetentionSetId”, “DatastoreIdentifier” : “DatastoreID”, “HostIdentifer” : “HostId”.
You can check the restore operation has started by listing the Tasks using the Get command with https://zerto_ip:port/v1/tasks.
So, why would I ever use this?
The backup API in particular has some great use cases, as Zerto uses the DR copy for Long-Term Retention operations meaning you can schedule a backup every 4-8 hours greatly reducing your offsite backup RPO without affecting your production environment. You can also schedule a backup operation after a particular application process has finished ensuring you have a recovery point to revert a service back to that particular time.