This page describes how to specify the order in which Backup for GKE
should restore different GroupKinds during a restore operation.

## Overview

By default, Backup for GKE restores well-known GroupKinds in an order that
fulfills dependency requirements among resources. However, if there are additional
resources that need restoring in a specific order, you can use the restore ordering
feature to specify the required order by defining dependencies between the affected
resources.

During a restore plan create or update operation, you can specify a list of
custom GroupKind dependencies. To represent a dependency between two custom
resources, specify the following two GroupKinds:

- Satisfying GroupKind: this GroupKind satisfies the dependencies and must be restored before the requiring GroupKind. In the Google Cloud console, this GroupKind is termed as the **First API group** and **First object kind** fields.
- Requiring GroupKind: this GroupKind depends on the satisfying GroupKind to be restored first. In the Google Cloud console, this GroupKind is termed as the **Second API group** and **Second object kind** fields.

Backup for GKE takes a list of custom dependencies and the
[default dependencies](https://docs.cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/how-to/restore-order.md.txt#default) and combines them to generate a GroupKind restore order.

## Default dependencies

The following table lists the default pairing dependencies between satisfying
and requiring GroundKind resources. When defining a restoring order,
Backup for GKE restores all satisfying GroundKinds before Requiring GroupKinds.
For example, Backup for GKE always restores all `storage.k8s.io/StorageClass`
before `PersistentVolumeClaims`.

The default restore ordering also handles basic cases, such as restoring
namespaces before all namespaced resources and restoring `CustomResourceDefinitions`
before any `CustomResources`.

| **Satisfying GroundKind resource** | **Requiring GroundKind resource** |
|---|---|
| flowcontrol.apiserver.k8s.io/PriorityLevelConfiguration | flowcontrol.apiserver.k8s.io/FlowSchema |
| storage.k8s.io/StorageClass | PersistentVolumeClaim |
| PersistentVolumeClaim | - Pod <!-- --> - Deployment <!-- --> - ReplicationController <!-- --> - ReplicaSet <!-- --> - StatefulSet <!-- --> - DaemonSet <!-- --> - CronJob <!-- --> - Job |
| ServiceAccount | - Pod <!-- --> - Deployment <!-- --> - ReplicationController <!-- --> - ReplicaSet <!-- --> - StatefulSet <!-- --> - DaemonSet <!-- --> - CronJob <!-- --> - Job |

## Define resource restore ordering

Use the following instructions to add custom GroupKind dependencies to a restore plan.
Refer to the list of [default dependencies](https://docs.cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/how-to/restore-order.md.txt#default) for all GroupKind dependencies
that are already handled by Backup for GKE and don't need to be specified.

### gcloud

1. Create a YAML file to define restore order. You can use the following YAML example.

   The following example indicates that `stable.example.com/First` must be
   restored before `stable.example.com/Second` and that `stable.example.com/Second`
   must be restored before `stable.example.com/Third`.

   ```yaml
     groupKindDependencies:
     - satisfying:
         resourceGroup: stable.example.com
         resourceKind: First
       requiring:
         resourceGroup: stable.example.com
         resourceKind: Second
     - satisfying:
         resourceGroup: stable.example.com
         resourceKind: Second
       requiring:
         resourceGroup: stable.example.com
         resourceKind: Third
   ```
2. Define a restore order using the restore order file you created.

   ```bash
   gcloud beta container backup-restore restore-plans update RESTORE_PLAN \
       --project=PROJECT_ID \
       --location=LOCATION \
       --restore-order-file=RESTORE_ORDER_FILE
   ```

   Replace the following:

- `RESTORE_PLAN`: the name of the restore plan that you want to update.
- `PROJECT_ID`: the ID of your Google Cloud project.
- `LOCATION`: the compute region of the parent restore plan.
- `RESTORE_ORDER_FILE`: the path to the YAML file containing the GroupKind dependencies, as shown in the earlier example.

### Console

Use the following instructions to add order to an existing restore plan in the Google Cloud console:

1. In the Google Cloud console, go to the **Google Kubernetes Engine** page.

   [Go to Google Kubernetes Engine](https://console.cloud.google.com/kubernetes/list)
2. In the navigation menu, click **Backup for GKE**.

3. Click the **Restore plans** tab.

4. Click the restore plan name.

5. Click the **Details** tab.

6. Click **Edit** that is next to the **Restore order**.

7. Click **Add order set**.

8. In the Item 1 section, enter **First API group 1** and **First object kind 1**
   followed by **Second API group 2** and **Second object kind 2** the order
   in which the resources to be restored.

9. Click **Save changes**.

## What's next

- Learn more about [restoring a backup](https://docs.cloud.google.com/kubernetes-engine/docs/add-on/backup-for-gke/how-to/restore.md.txt).