// Module included in the following assemblies:
//
// * cloud_experts_tutorials/cloud-experts-deploy-api-data-protection.adoc

:_mod-docs-content-type: PROCEDURE
[id="cloud-experts-deploy-api-data-protection-perform-backup_{context}"]
= Back up and restore a workload

[role="_abstract"]
Back up and restore a workload to verify that {oadp-full} is working correctly on your cluster.

[NOTE]
====
The following sample `hello-world` application has no attached persistent volumes. Either Data Protection Application (DPA) configuration will work.
====

.Procedure
. Create a workload to back up:
.. Create a namespace by running:
+
[source,terminal]
----
$ oc create namespace hello-world
----
.. Create an application by running:
+
[source,terminal]
----
$ oc new-app -n hello-world --image=docker.io/openshift/hello-openshift
----

. Expose the route:
+
[source,terminal]
----
$ oc expose service/hello-openshift -n hello-world
----

. Check that the application is working:
+
[source,terminal]
----
$ curl `oc get route/hello-openshift -n hello-world -o jsonpath='{.spec.host}'`
----
+
.Example output
[source,terminal]
----
Hello OpenShift!
----

. Back up the workload:
+
[source,terminal]
----
$ cat << EOF | oc create -f -
apiVersion: velero.io/v1
kind: Backup
metadata:
 name: hello-world
 namespace: openshift-adp
spec:
 includedNamespaces:
 - hello-world
 storageLocation: ${CLUSTER_NAME}-dpa-1
 ttl: 720h0m0s
EOF
----

. Wait until the backup is done:
+
[source,terminal]
----
$ watch "oc -n openshift-adp get backup hello-world -o json | jq .status"
----
+
.Example output
[source,JSON]
----
{
 "completionTimestamp": "2022-09-07T22:20:44Z",
 "expiration": "2022-10-07T22:20:22Z",
 "formatVersion": "1.1.0",
 "phase": "Completed",
 "progress": {
   "itemsBackedUp": 58,
   "totalItems": 58
 },
 "startTimestamp": "2022-09-07T22:20:22Z",
 "version": 1
}
----

. Delete the demo workload:
+
[source,terminal]
----
$ oc delete ns hello-world
----

. Restore from the backup:
+
[source,terminal]
----
$ cat << EOF | oc create -f -
apiVersion: velero.io/v1
kind: Restore
metadata:
 name: hello-world
 namespace: openshift-adp
spec:
 backupName: hello-world
EOF
----

. Wait for the restore to finish:
+
[source,terminal]
----
$ watch "oc -n openshift-adp get restore hello-world -o json | jq .status"
----
+
.Example output
[source,JSON]
----
{
 "completionTimestamp": "2022-09-07T22:25:47Z",
 "phase": "Completed",
 "progress": {
   "itemsRestored": 38,
   "totalItems": 38
 },
 "startTimestamp": "2022-09-07T22:25:28Z",
 "warnings": 9
}
----

. Check that the workload is restored:
+
[source,terminal]
----
$ oc -n hello-world get pods
----
+
.Example output
[source,terminal]
----
NAME                              READY   STATUS    RESTARTS   AGE
hello-openshift-9f885f7c6-kdjpj   1/1     Running   0          90s
----
+
[source,terminal]
----
$ curl `oc get route/hello-openshift -n hello-world -o jsonpath='{.spec.host}'`
----
+
.Example output
[source,terminal]
----
Hello OpenShift!
----
