Veeam Backup (veeamzip) using vRO

Veeam Backup (veeamzip) using vRO

Hi all,

I just finished finished working though the REST of VEeam in order to create a VeeamZip using VRO. Here is what I learned.

Veeam (version 9) has quite a nice REST and its not that bad documented when you start getting the hang of it. You find the full veeam REST docu here: https://helpcenter.veeam.com/backup/rest/em_web_api_reference.html

There is a nice tutorial that gets you started: https://helpcenter.veeam.com/backup/rest/getting_started_with_em_web_api.html

Veeam is XML based, so you ned to know how to work with XML in VRA (see Publications)

Adding the VEEAM REST host:

  1. Login to vRO Client
  2. Start the workflow: Library | HTTP-REST | Add a REST host
  3. The URL is either http://[veeamserver]:9399 or https://[veeamserver]:9398
  4. Use Basic security and the credentials of an user that has the Veeam Backup Administrator role

Logon & Logoff

  • The logon process is by POSTing to the session Manager. The return contains a session ID that we need for logoff or for further actions.

var PostResponse = veeamHost.createRequest("POST", "/api/sessionMngr/?v=v1_1", null).execute();

xmldoc=XMLManager.fromString(PostResponse.contentAsString);

var sessionID = ((xmldoc.getElementsByTagName("SessionId")).item(0)).textContent;

  • logoff is simply done by DELETEing the session

var PostResponse = veeamHost.createRequest("DELETE", "/api/logonSessions/"+sessionID, null).execute();

Creating the veeamzip

We need the following REST call to creat a veeam Zip : https://helpcenter.veeam.com/backup/rest/post_backupservers_id_zip.html

Boiling down to the following XML we have to post:

POST http://localhost:9399/api/backupServers/f365fbd8-fbd2-43ad-9f7a-c87cd390a0d9?action=veeamzip

<?xml version="1.0" encoding="utf-8"?>

<VeeamZipStartupSpec xmlns="http://www.veeam.com/ent/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <VmRef>urn:VMware:Vm:a9850703-e3fd-43d8-8f30-6d7fba40b6dd.vm-38856</VmRef>

  <RepositoryUid>urn:veeam:Repository:b609c947-dd30-4295-8b57-cc880329dbd6</RepositoryUid>

  <CompressionLevel>5</CompressionLevel>

  <DisableGuestQuiescence>false</DisableGuestQuiescence>

  <BackupRetention>Never</BackupRetention>

</VeeamZipStartupSpec>

Lets discuss the three IDs we need from veeam before we can get started (highlighted above):

The backupServer ID is the veeam server that is used to create the request. You can get it using:

var PostResponse = veeamHost.createRequest("GET", "/api/backupServers", null).execute();

System.log(PostResponse.contentAsString);

The VmRef is made out of the ID for the attached vCenter and the VM.id (the vCenter moRef). Its called a hierarchy in Veeam. You get the existing hierarchy by:

var PostResponse = veeamHost.createRequest("GET", "/api/hierarchyRoots", null).execute();

System.log(PostResponse.contentAsString);

The repository ID represents the storage where you will store the VeeamZip. You can get that by using:

var PostResponse = veeamHost.createRequest("GET", "/api/repositories", null).execute();

System.log(PostResponse.contentAsString);

To create the Veeamzip I used the following code:

xml='<?xml version="1.0" encoding="utf-8"?><VeeamZipStartupSpec xmlns="http://www.veeam.com/ent/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><VmRef>urn:VMware:Vm:'+hiracy+'.'+vcvm.id+'</VmRef><RepositoryUid>urn:veeam:Repository:'+repository+'</RepositoryUid><CompressionLevel>3</CompressionLevel><DisableGuestQuiescence>false</DisableGuestQuiescence><BackupRetention>Never</BackupRetention></VeeamZipStartupSpec>';

var request  = veeamHost.createRequest("POST", "/api/backupServers/"+veeamServer+"?action=veeamzip", xml);

request.contentType = "application\/xml";

request.setHeader("Accept", "application/xml");

var response = request.execute();

In order to check if the task has finished I used:

xmldoc=XMLManager.fromString(response.contentAsString);

var veeamTask = ((xmldoc.getElementsByTagName("TaskId")).item(0)).textContent;

do{

    System.sleep(500);

    var PostResponse = veeamHost.createRequest("GET", "/api/tasks/"+veeamTask, null).execute();

    xmldoc=XMLManager.fromString(PostResponse.contentAsString);

    var state = ((xmldoc.getElementsByTagName("State")).item(0)).textContent;

} while (state !="Finished")

Check up on the state of the backup

The task only shows up for some 5-10 seconds and then it shows finished, however the backup job isnt finished yet. To check up on the Backup job use this

var PostResponse = veeamHost.createRequest("GET", "/api/backupSessions", null).execute();

xmldoc=XMLManager.fromString(PostResponse.contentAsString);

refs=xmldoc.getDocumentElement().getChildNodes();

for (i=0;i<refs.length;i++){

    ref=refs.item(i);

    refAtt=ref.getAttributes();

    jobName=(refAtt.getNamedItem("Name")).nodeValue

    if (jobName.indexOf(vm.name)>=0){

        jobUID=(refAtt.getNamedItem("UID")).nodeValue;

        jobID=(jobUID.split(":"))[3];

        var jobGET = veeamHost.createRequest("GET", "/api/backupSessions/"+jobID+"?format=Entity", null).execute();

        xmlBack=XMLManager.fromString(jobGET.contentAsString);

        state=((xmlBack.getElementsByTagName("Result")).item(0)).textContent;

        break;

    }

}

Example Package

Attached is my code as a package...have fun!

The Package contains 3 workflows and a configuration. Use AddVeeamHost to add the veeam as REST client, it also outputs all the XML to get the IDs. The getVeeamStuff gets all the IDs you need. Go and add the IDs and the link to the veeam host to the configuration and then use createVeeamZip to create a veeamZip of a VM


Attachments
Version history
Revision #:
1 of 1
Last update:
‎09-27-2016 01:50 AM
Updated by: