Automation
The bigger the environment, the more automation is needed to reduce the administration effort. For example, if you are operating 40 branch offices with independent Veeam installations, you may want to roll out and configure backup servers with scripts, and automatically create jobs in the same location. Another example is automatic job creation for 2,000-3,000 VMs with exactly the same configurations, which can limit user-caused misconfiguration.
Command line
Following operations are managed through the Windows command line:
Installation - Link to Help Center
Updates - Link to Help Center
PowerShell
Operations in Veeam Backup & Replication can be automated with Veeam PowerShell snap-in in the following areas:
Configuration
Job creation/job editing
Working with external schedulers (UC4/TWS and other) to start Veeam jobs
Restores
Reporting
Datacenter migration (quick migration or replication)
The PowerShell plugin is available with all commercial versions of the product.
Note: PowerShell plugin is also available with Veeam Backup FREE, although limited: https://www.veeam.com/blog/veeam-backup-free-edition-now-with-powershell.html
Our customers and partners use this functionality to scale out backup infrastructure environments to nearly 100,000 VMs under a single Veeam Backup Enterprise Manager instance with multiple backup servers located in different datacenters.
The best starting point to get in touch with the Veeam PowerShell plugin is to read the Veeam PowerShell User Guide > Veeam Help Center - PowerShell Reference.
You can find help for the scripts in the Veeam Community Forums - PowerShell section. If you need some examples, refer to the following thread: Getting Started and Code Examples
RESTful API
In the Veeam Enterprise Manager, there is as well RESTful API that allows you to create workflows in orchestration tools or to integrate Veeam Backup Enterprise Manager (self-services) in your own “cloud” portal. Specifically, this is an option that comes with Enterprise Plus Editions and is focused on the hosting business.
Here is a list of external resources:
A simple RESTful API example - adding a guest to a backup job
In the following section, the Veeam WEB client will be used for convenience as it is quite simple by nature and instantly available through enterprise manager URL. Also, the browser used is configured to accept cookies to simplify the authentication token management.
Authentication on the REST server
From the client browser, connect to the URL http://EM:9399/web/#/api/ and enter credentials as requested. Then, follow the latest version URL to get the list of all accessible resources types. http://EM:9399/web/#/api/sessionMngr/?v=latest
Building a query to retrieve the vCenter UID
Once logged in, knowing the vCenter Name where the VM we want to add resides, we need to get the vCenter UID.
Refering to the REST API guide https://helpcenter.veeam.com/docs/backup/rest/get_managedservers_id.html?ver=95 we can gather necessary informations to build a query.
Object type is “ManagedServer”
Property to filter is “ManagedServerType” from which “VC” corresponds to vCenter
Property to filter is “Name” equal to “vc.democenter.int” in this example
Note: the “ManagedServerType” has been added to the query for demonstration purpose.
The lookup service necessitates a “HierarchyRoot” resource type in the urn, which is an alternate representation of the “ManagedServer”. We then must send a GET to the managed server resource representation: http://EM:9399/web/#/api/managedServers/25fb843d-92a3-45d4-836c-0531afe4df9b?format=Entity and find the “Alternate” representation of type “HierarchyRoot” in the proposed links.
From here, send a GET request to the HierarchyRoot resource representation to pick up its UID (simply clicking on the URL will send the GET request).
The required reference for further use is the UID “urn:veeam:HierarchyRoot:93fe5565-0ae7-4574-abb5-0f4ea8c5e9bd” corresponding to the Veeam managed vCenter server where the VM should reside.
Note: It could have been more simple to directly work on the ManagedServer UID and directly change the resource type from “ManagedServer” to “HierarchyRoot”. The complex method was chosen for demonstration purpose.
Building a lookup to retrieve the virtual machine ID
Knowing the UID of the “Host” (vCenter), and the name of the guest we want to add to a job, we can build the lookup URL using the name of the VM as a selection criteria. The rules to build the lookup request are detailed in the REST API guide : https://helpcenter.veeam.com/docs/backup/rest/lookup_query.html?ver=95#params.
The UID here is given by the “ObjectRef” property: “urn:VMware:Vm:93fe5565-0ae7-4574-abb5-0f4ea8c5e9bd.vm-48911”. As you can see, the UID of the VM comprises the UID of the management server appended with the Mo-Ref of the VM. This is useful if you want to automatically build a Veeam VM reference, knowing its management server and Mo-Ref. This “manual” type construction of references can be used for automation purpose.
Building a query to retrieve the Job ID
Knowing the Name of the job where the VM should be added (“Test REST”) we can request the query service to get its ID:
http://hq-vbrem1.democenter.int:9399/web/#/api/query?type=job&filter=(Name==%22Test REST%22)
The ID is given by the last part of the Ref UID : “urn:veeam:Job:455c0799-ede5-4ade-a7b2-02d2d0fac3de”. The URL to access the job resource representation is directly given by the link pointing to the “JobReference” type: http://hq-vbrem1.democenter.int:9399/api/jobs/455c0799-ede5-4ade-a7b2-02d2d0fac3de
Note: To access the resource (not the resource representation) and get more details, you shall follow the “Alternate” related object, which type is “Job” and not “JobReference”.
Adding the VM to the job
Knowing the “Jobs” resource representation structure, the resource to be called to add the VM to the job is "/jobs/{ID}/includes" with a POST verb. In case of any doubt about the resource to call, the REST reference guide offers a precise representation of the resource tree: https://helpcenter.veeam.com/docs/backup/rest/post_jobs_id_includes.html?ver=95
As stated by the “Min/Max” column, the only mandatory parameters to add in the request body are the container reference (a VM in our example) and name “HierarchyObjRef” and “HierarchyObjName”.
All other guest related parameters are described in the documentation. Specific credentials for inguest processing are described by the resource “/backupServers/{ID}/credentials”.
Order
GuestProcessingOptions
VssSnapshotOptions
WindowsGuestFSIndexingOptions
LinuxGuestFSIndexingOptions
SQLBackupOptions
WindowsCredentialsId
LinuxCredentialsId
FSFileExcludeOptions
OracleBackupOptions
We will then form a HTTP phrase: Type: POST
URL: http://hq-vbrem1.democenter.int:9399/web/#/api/jobs/455c0799-ede5-4ade-a7b2-02d2d0fac3de/includes
Header: (automatically handled by the client since cookies are in use) :
Cookie: X-RestSvcSessionId=Session_ID
Body:
To access the POST request from the Veeam WEB client, open the resource view of the job ID 455c0799-ede5-4ade-a7b2-02d2d0fac3de and follow the proposed link leading to add a VM in the job (Type=”ObjectInJob”, Rel=”Create”).
This will automatically form the HTTP request :
From there, the body can be modified to indicate proper VM reference:
Upon completion, a return code 200 should be sent by the server, pointing to the corresponding task.
To verify if the added VM is in the job, we can send a quuery using the “ObjectInJob” type as described in the available querying type (refer to user guide “Query Syntax” section for more informations). The possible filter parameters are described in the “(GET) /jobs/{ID}/includes/{ID}” section of the reference guide.
http://hq-vbrem1.democenter.int:9399/web/#/api/query?type=ObjectInJob&filter=(JobName==”Test REST”;Name==”demo-win1”)
Closing the connection
The final step is to close the connection. Using the VEEAM REST client, closing the client will close the connection. Using any other client, a DELETE should be sent to the session resource representation (leaving the body empty, as the session is referenced to in the URL as a resource).
Last updated