bob-builds-labs

PPDM Self Service Restore

PPDM allows developers to restore namespace from kubernetes api. thi can be done by leveraging the RestoreJobs CRD.

To get a list of recent Backups done by PPDM, query for backupjobs resource in the PPDM Namespace

oc get backupjobs -n powerprotect

image

let´s have a look at the content of the latest backup:

oc get backupjobs -n powerprotect -o "jsonpath-as-json={.items[-1]}"

take you time to review the output

image

lets use some jq magic to query for the latest backup of wordpress:

oc get backupjobs -n powerprotect -o json | jq -r '[.items[] | select(.metadata.name | test("wordpress-")).metadata.name] | last'

image

and use this as the input for the restore job:

Creating the Restore Job

the below code represents the content of the script restore_new_alternate_sc.s esentially, it create a Restore Job that gets populated with required data from the BackupJob (asset, CredentialID) , and the inputs parameters for restorejob, new namespace and alternate SC

o not run below code:

BACKUP_CONTENT=$(kubectl get backupjobs/"${BACKUP_JOB}" -n powerprotect -o json)
CREDENTIALID=$(echo "${BACKUP_CONTENT}" | jq  .metadata.annotations.storageUnit)
ASSET=$(echo "${BACKUP_CONTENT}" | jq -r .metadata.annotations.asset)
RESTORE_JOB="restore-${ASSET}-$(date +"%Y-%m-%d-%H-%M-%S")"
cat << EOF | kubectl apply -f -
apiVersion: "powerprotect.dell.com/v1beta1"
kind: RestoreJob
metadata:
  name: ${RESTORE_JOB}
  namespace: powerprotect
spec:
  recoverType: RestoreToNew #Default is RestoreToOriginal
  backupJobName: ${BACKUP_JOB} # For e.g. testapp1-2019-11-16-14-15-47
  namespaces:
  - name: ${ASSET}
    alternateNamespace: ${NEW_NS} # Name for the
    persistentVolumeClaims:
    - name: "*" #volumes to be recovered. By default all volumes backed up
      alternateStorageClass: ${ALTERNATE_SC}
EOF

as we are going to run the script:

./restore_new_alternate_sc.sh $(oc get backupjobs -n powerprotect -o json | jq -r '[.items[] | select(.metadata.name | test("wordpress-")).metadata.name] | last') test3 thin-csi-immediate

image

once the status shows success, you can use crtl-c to exit the script

image

Back to Index