16.4. Backing Up and Restoring Virtual Machines Using the Backup and Restore API 16.4.1. The Backup and Restore API The backup and restore API is a collection of functions that allows you to perform full or file-level backup and restoration of virtual machines. The API combines several components of Red Hat Virtualization, such as live snapshots and the REST API, to create and work with temporary volumes that can be attached to a virtual machine containing backup software provided by an independent software provider. For supported third-party backup vendors, consult the Red Hat Virtualization Ecosystem . 16.4.2. Backing Up a Virtual Machine Use the backup and restore API to back up a virtual machine. This procedure assumes you have two virtual machines: the virtual machine to back up, and a virtual machine on which the software for managing the backup is installed. Backing Up a Virtual Machine Using the REST API, create a snapshot of the virtual machine to back up: Note Here, replace {vm:id} with the VM ID of the virtual machine whose snapshot you are making. This ID is available from the General tab of the New Virtual Machine and Edit Virtual Machine windows in the Administration Portal and VM Portal . Taking a snapshot of a virtual machine stores its current configuration data in the data attribute of the configuration attribute in initialization under the snapshot. Important You cannot take snapshots of disks marked as shareable or based on direct LUN disks. Retrieve the configuration data of the virtual machine from the data attribute under the snapshot: Note Here, replace {vm:id} with the ID of the virtual machine whose snapshot you made earlier. Replace {snapshot:id} with the snapshot ID. Add the All-Content: true header to retrieve additional OVF data in the response. The OVF data in the XML response is located within the VM configuration element, <initialization><configuration> . Later, you will use this data to restore the virtual machine. Get the snapshot ID: Identify the disk ID of the snapshot: Attach the snapshot to a backup virtual machine as an active disk attachment, with the correct interface type (for example, virtio_scsi ): Note Here, replace {vm:id} with the ID of the backup virtual machine, not the virtual machine whose snapshot you made earlier. Replace {disk:id} with the disk ID. Replace {snapshot:id} with the snapshot ID. Use the backup software on the backup virtual machine to back up the data on the snapshot disk. Remove the snapshot disk attachment from the backup virtual machine: Note Here, replace {vm:id} with the ID of the backup virtual machine, not the virtual machine whose snapshot you made earlier. Replace {snapshot:id} with the snapshot ID. Optionally, delete the snapshot: Note Here, replace {vm:id} with the ID of the virtual machine whose snapshot you made earlier. Replace {snapshot:id} with the snapshot ID. You have backed up the state of a virtual machine at a fixed point in time using backup software installed on a separate virtual machine. 16.4.3. Restoring a Virtual Machine Restore a virtual machine that has been backed up using the backup and restore API. This procedure assumes you have a backup virtual machine on which the software used to manage the backup is installed. Restoring a Virtual Machine In the Administration Portal, create a floating disk on which to restore the backup. See Section 13.6.1, "Creating a Virtual Disk" for details on how to create a floating disk. Attach the disk to the backup virtual machine: Note Here, replace {vm:id} with the ID of this backup virtual machine, not the virtual machine whose snapshot you made earlier. Replace {disk:id} with the disk ID you got while backing up the virtual machine. Use the backup software to restore the backup to the disk. Detach the disk from the backup virtual machine: + NOTE: Here, replace {vm:id} with the ID of this backup virtual machine, not the virtual machine whose snapshot you made earlier. Replace {disk:id} with the disk ID. Create a new virtual machine using the configuration data of the virtual machine being restored: Note To override any of the values in the ovf while creating the virtual machine, redefine the element before or after the initialization element. Not within the initialization element. Attach the disk to the new virtual machine: Note Here, replace {vm:id} with the ID of the new virtual machine, not the virtual machine whose snapshot you made earlier. Replace {disk:id} with the disk ID. You have restored a virtual machine using a backup that was created using the backup and restore API.

Commands:
POST /api/vms/ {vm:id} /snapshots/ HTTP/1.1 Accept: application/xml Content-type: application/xml <snapshot> <description>BACKUP</description> </snapshot>
GET /api/vms/ {vm:id} /snapshots/ {snapshot:id} HTTP/1.1 All-Content: true Accept: application/xml Content-type: application/xml
GET /api/vms/{vm:id}/snapshots/ HTTP/1.1 Accept: application/xml Content-type: application/xml
GET /api/vms/ {vm:id} /snapshots/ {snapshot:id} /disks HTTP/1.1 Accept: application/xml Content-type: application/xml
POST /api/vms/ {vm:id} /diskattachments/ HTTP/1.1 Accept: application/xml Content-type: application/xml <disk_attachment> <active>true</active> <interface>_virtio_scsi_</interface> <disk id=" {disk:id} "> <snapshot id=" {snapshot:id} "/> </disk> </disk_attachment>
DELETE /api/vms/ {vm:id} /diskattachments/ {snapshot:id} HTTP/1.1 Accept: application/xml Content-type: application/xml
DELETE /api/vms/ {vm:id} /snapshots/ {snapshot:id} HTTP/1.1 Accept: application/xml Content-type: application/xml
POST /api/vms/ {vm:id} /disks/ HTTP/1.1 Accept: application/xml Content-type: application/xml <disk id=" {disk:id} "> </disk>
DELETE /api/vms/ {vm:id} /disks/ {disk:id} HTTP/1.1 Accept: application/xml Content-type: application/xml <action> <detach>true</detach> </action>
POST /api/vms/ HTTP/1.1 Accept: application/xml Content-type: application/xml <vm> <cluster> <name>cluster_name</name> </cluster> <name>_NAME_</name> <initialization> <configuration> <data> <!-- omitting long ovf data --> </data> <type>ovf</type> </configuration> </initialization> </vm>
POST /api/vms/ {vm:id} /disks/ HTTP/1.1 Accept: application/xml Content-type: application/xml <disk id=" {disk:id} "> </disk>