This document describes how to create a virtual machine (VM) from an existing
backup in Google Distributed Cloud (GDC) air-gapped.

After a backup is created, you can create a restore for that backup, which
initiates the restoration of the entire VM. The restored VM
and its associated disks have different names based on what you specify as the
**New VM instance name** in the GDC console, or the
`restoredResourceName` in the application programming interface (API).

When a backup is restored, the entire VM is restored. After the resources are
created, actual restoration of application capability is subject to the VM
operating system or image.

This document is for developers in platform administrator or application operator
groups that manage VM backup and restore operations. For more information, see
[Audiences for GDC air-gapped documentation](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/resources/audiences.md.txt).

## Before you begin

Ensure you have an existing backup. For more information, see
[Create a backup plan](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/platform-application/pa-ao-operations/vm-backup/backup-plans/create-scheduled-backup-plan.md.txt).

### Request IAM roles

To create a VM from a backup, ask your IAM Project Admin to grant you the
following roles:

- **Virtual Machine Project Admin** (`project-vm-admin`): creates, gets, lists,
  watches,
  updates, patches, and deletes virtual machines and VM disks in project namespaces.

- **Backup Creator** (`backup-creator`): creates, gets, lists, watches, updates, patches,
  and deletes manual backup requests and manual restore requests.

- **Project Viewer** (`project-viewer`): gets, lists, and watches all resources within project
  namespaces.

Follow the steps to [verify](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/application/ao-user/vms/preparation.md.txt#verify-user-access)
your access.

## Create a restore for VMs

Restore a VM backup using the GDC console or the API.

### Console

1. Sign in to the GDC console.
2. In the navigation menu, click **Backup for Virtual Machines**.
3. Select a project.
4. Click the **Backups** tab.
5. In the list of backups, find the backup that you want to restore and click **Restore**.
6. In the **New VM instance name** field, enter a name for the new target virtual instance to restore the backup in.
7. Optional: In the **New VM instance** description field, enter a description.
8. Enter a **Name** for the restore.
9. Click **Restore**.

### API

Define a `VirtualMachineRestoreRequest` custom resource to initiate the restore
process. The referenced backup in the `virtualMachineBackup` field refers to a
`VirtualMachineBackup` custom resource generated by a
`VirtualMachineBackupRequest`. Here's an example of a
`VirtualMachineRestoreRequest`:

Define a `VirtualMachineRestoreRequest` custom resource to initiate the
restore process:

```yaml
apiVersion: virtualmachine.gdc.goog/v1
kind: VirtualMachineRestoreRequest
metadata:
  name: RESTORE_REQUEST_NAME
  namespace: PROJECT_NAME
spec:
  virtualMachineBackup: VM_BACKUP_NAME
  restoreName: RESTORE_NAME
  restoredResourceName: RESTORED_RESOURCE_NAME
  restoredResourceDescription: RESTORED_RESOURCE_DESCRIPTION
```

Replace the following:

- `VM_BACKUP_NAME`: the name of the `VirtualMachineBackup` to restore from.
- `PROJECT_NAME`: the name of the GDC project.
- `RESTORE_REQUEST_NAME`: the name to give the restore request that is being initiated.
- `RESTORE_NAME`: name to give the restore that is being initiated.
- `RESTORED_RESOURCE_NAME`: the name to give the restored VM.
- `RESTORED_RESOURCE_DESCRIPTION`: notes for why the restore is being performed.

The result of the restore creates a new VM with the same configuration and disk
state as the backup.

### View a restore for VMs

View a list of restores using the GDC console:

1. Sign in to the GDC console.
2. In the navigation menu, click **Backup for Virtual Machines**.
3. Select a project.
4. Click the **Restores** tab.
5. Click a restore in the list to view its details.

## Delete a restore

Delete a restore by using the GDC console or `kubectl`.

### Console

1. Sign in to the GDC console.
2. In the navigation menu, click **Backup for Virtual Machines**.
3. Select a project.
4. Click the **Restores** tab.
5. In the list of restores, find the restore to delete and click **Delete Restore**.
6. In the **Restore name** field, enter the name of the restore to delete.
7. Click **Delete Restore**.

### kubectl

1. List the existing restores:

   ```bash
   kubectl get virtualmachinerestores.virtualmachine.gdc.goog -n PROJECT_NAME
   ```

   Replace `PROJECT_NAME` with the name of the project.
2. In the list, find the restore that you want to delete.

3. Delete the restore:

   ```bash
   kubectl delete virtualmachinerestores.virtualmachine.gdc.goog RESTORE_NAME -n PROJECT_NAME
   ```

   Replace the following:
   - `RESTORE_NAME`: the name of the restore.
   - `PROJECT_NAME`: the name of the project.