This page guides you through how to prevent potential data loss or restore
failures when working with disks that were restored from backups of disks
attached to virtual machines (VMs).

Restoring an individual disk that was attached to a VM can leave behind specific
labels on the restored disk resource and its underlying `PersistentVolumeClaim`
(PVC) resource. Failure to remove the labels as described can lead to:

- Failures during subsequent full VM restore operations.
- Unintended modification or replacement of the restored disk's underlying PVC during a subsequent full VM restore, potentially leading to data loss on the restored disk.

> [!IMPORTANT]
> **Important:** These steps are mandatory immediately after you restore an individual disk if that disk was originally attached to a VM, especially if you intend to perform full VM backups and restores involving the original VM at a later time.

## Before you begin

To clean up the labels after restoring a VM-attached disk, you must have the following:

- The necessary identity and access role. Ask your IAM Org Admin to grant you the Database Debugger (`dbs-debugger`) role.
- Access to the appropriate kubeconfig files for the clusters managing these resources.
- The kubectl command-line tool installed and configured.

## Clean up labels

You must perform the cleanup for both the `VirtualMachineDisk` resource and its underlying `PersistentVolumeClaim` (PVC) resource.

### Clean up the VM disk labels

To clean up the labels of a restored VM disk, follow these steps:

1. Get the kubeconfig file for the management API server and set the
   `KUBECONFIG` environment variable:

   ```bash
   export KUBECONFIG=PATH_TO_MANAGEMENT_API_KUBECONFIG
   ```

   Replace `PATH_TO_MANAGEMENT_API_KUBECONFIG` with the
   path to the kubeconfig file. For more information, see [Zonal Management API
   server
   resources](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/gdcag/platform/pa-user/iam/sign-in#zonal-resources-kubeconfig).
2. Check that the restored `VirtualMachineDisk` resource exists in the specified namespace:

   ```bash
   kubectl get virtualmachinedisks.virtualmachine.gdc.goog \
   -n NAMESPACE RESTORED_VM_DISK_NAME
   ```

   Replace the following:
   - `NAMESPACE`: the project namespace.
   - `RESTORED_VM_DISK_NAME`: the full name of the restored disk using the values gathered in the prerequisites. The value for this variable can be derived from `RESTORED_PREFIX`-`VM_DISK_NAME`.
3. Remove the backup scope label from the `VirtualMachineDisk` resource. The trailing hyphen after the label key signifies removal:

   ```bash
   kubectl label virtualmachinedisks.virtualmachine.gdc.goog -n NAMESPACE \
       RESTORED_VM_DISK_NAME bpvms/VM_NAME-
   ```

   Replace `VM_NAME` with the name of the restored VM.
4. Optional: To verify that the `bpvms/VM_NAME` label is no longer present, you can re-run the corresponding `kubectl get` command, adjusting for the specific resource type and cluster:

   ```bash
   kubectl get virtualmachinedisks.virtualmachine.gdc.goog \
   -n NAMESPACE VM_NAME
   ```

### Clean up the PVC labels

To clean up the labels of the underlying PVC, follow these steps:

1. Get the kubeconfig file for the org infrastructure cluster and set the `KUBECONFIG` environment variable:

   ```bash
   export KUBECONFIG=PATH_TO_ORG_INFRA_KUBECONFIG
   ```

   Replace `PATH_TO_ORG_INFRA_KUBECONFIG` with the path
   to the kubeconfig file.
2. Check that the underlying PVC for the restored disk exists in the specified namespace:

   ```bash
   kubectl get pvc -n NAMESPACE \
       RESTORED_VM_DISK_NAME
   ```

   Replace the following:
   - `NAMESPACE`: the project namespace.
   - `RESTORED_VM_DISK_NAME`: the name of the restored VM disk.
3. Remove the backup scope label from the PVC. The trailing hyphen after the label key signifies removal:

   ```bash
   kubectl label pvc -n NAMESPACE RESTORED_VM_DISK_NAME bpvms/VM_NAME-
   ```

   Replace `VM_NAME` with the name of the restored VM.
4. Optional: To verify that the `bpvms/VM_NAME` label is no longer present, you can re-run the corresponding `kubectl get` command, adjusting for the specific resource type and cluster:

   ```bash
   kubectl get pvc -n NAMESPACE \
       VM_NAME
   ```