// Module included in the following assemblies:
//
// * hosted_control_planes/hcp-disaster-recovery-oadp.adoc

:_mod-docs-content-type: PROCEDURE
[id="hcp-dr-oadp-backup-cp-workload-aws_{context}"]
= Backing up the control plane workload on {aws-short}

[role="_abstract"]
You can back up the control plane workload by creating the `Backup` custom resource (CR).

For information about monitoring the backup process, see "Observing the backup and restore process".

.Procedure

. Pause the reconciliation of the `HostedCluster` resource by running the following command:
+
[source,terminal]
----
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
  patch hostedcluster -n <hosted_cluster_namespace> <hosted_cluster_name> \
  --type json -p '[{"op": "add", "path": "/spec/pausedUntil", "value": "true"}]'
----

. Get the infrastructure ID of your hosted cluster by running the following command:
+
[source,terminal]
----
$ oc get hostedcluster -n local-cluster <hosted_cluster_name> -o=jsonpath="{.spec.infraID}"
----
+
Note the infrastructure ID to use in the next step.

. Pause the reconciliation of the `cluster.cluster.x-k8s.io` resource by running the following command:
+
[source,terminal]
----
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
  patch cluster.cluster.x-k8s.io \
  -n local-cluster-<hosted_cluster_name> <hosted_cluster_infra_id> \
  --type json -p '[{"op": "add", "path": "/spec/paused", "value": true}]'
----

. Pause the reconciliation of the `NodePool` resource by running the following command:
+
[source,terminal]
----
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
  patch nodepool -n <hosted_cluster_namespace> <node_pool_name> \
  --type json -p '[{"op": "add", "path": "/spec/pausedUntil", "value": "true"}]'
----

. Pause the reconciliation of the `AgentCluster` resource by running the following command:
+
[source,terminal]
----
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
  annotate agentcluster -n <hosted_control_plane_namespace>  \
  cluster.x-k8s.io/paused=true --all'
----

. Pause the reconciliation of the `AgentMachine` resource by running the following command:
+
[source,terminal]
----
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
  annotate agentmachine -n <hosted_control_plane_namespace>  \
  cluster.x-k8s.io/paused=true --all'
----

. Annotate the `HostedCluster` resource to prevent the deletion of the hosted control plane namespace by running the following command:
+
[source,terminal]
----
$ oc --kubeconfig <management_cluster_kubeconfig_file> \
  annotate hostedcluster -n <hosted_cluster_namespace> <hosted_cluster_name> \
  hypershift.openshift.io/skip-delete-hosted-controlplane-namespace=true
----

. Create a YAML file that defines the `Backup` CR:
+
.Example `backup-control-plane.yaml` file
[source,yaml]
----
apiVersion: velero.io/v1
kind: Backup
metadata:
  name: <backup_resource_name>
  namespace: openshift-adp
  labels:
    velero.io/storage-location: default
spec:
  hooks: {}
  includedNamespaces:
  - <hosted_cluster_namespace>
  - <hosted_control_plane_namespace>
  includedResources:
  - sa
  - role
  - rolebinding
  - pod
  - pvc
  - pv
  - bmh
  - configmap
  - infraenv
  - priorityclasses
  - pdb
  - agents
  - hostedcluster
  - nodepool
  - secrets
  - services
  - deployments
  - hostedcontrolplane
  - cluster
  - agentcluster
  - agentmachinetemplate
  - agentmachine
  - machinedeployment
  - machineset
  - machine
  excludedResources: []
  storageLocation: default
  ttl: 2h0m0s
  snapshotMoveData: true
  datamover: "velero"
  defaultVolumesToFsBackup: true
----
+
* `metadata.name` specifies the name of your `Backup` resource.
* `spec.includedNamespaces` includes specific namespaces to back up objects from them. You must replace `<hosted_cluster_namespace>` with the name of the hosted cluster namespace and replace `<hosted_control_plane_namespace>` with the name of the hosted control plane namespace.
* `spec.includedResources` includes the `infraenv` resource. You must create the `infraenv` resource in a separate namespace. Do not delete the `infraenv` resource during the backup process.
* `spec.snapshotMoveData` and `spec.datamover` enable the CSI volume snapshots and upload the control plane workload automatically to the cloud storage.
* `spec.defaultVolumesToFsBackup` sets the `fs-backup` backing up method for persistent volumes (PVs) as default. This setting is useful when you use a combination of Container Storage Interface (CSI) volume snapshots and the `fs-backup` method.
+
[NOTE]
====
If you want to use CSI volume snapshots, you must add the `backup.velero.io/backup-volumes-excludes=<pv_name>` annotation to your PVs.
====

. Apply the `Backup` CR by running the following command:
+
[source,terminal]
----
$ oc apply -f backup-control-plane.yaml
----

.Verification

* Verify if the value of the `status.phase` is `Completed` by running the following command:
+
[source,terminal]
----
$ oc get backups.velero.io <backup_resource_name> -n openshift-adp \
  -o jsonpath='{.status.phase}'
----

.Next steps

* Restoring a hosted cluster by using OADP
