From 5c601166e5602e1d5844a09e83137fb221608542 Mon Sep 17 00:00:00 2001 From: Michael Haswell Date: Fri, 26 Jan 2024 10:09:13 -0800 Subject: [PATCH 1/2] Created backup-restore.yaml Job Template to make restoring from a backup easier Updated README to explain usage of backup-restore --- helm/Chart.yaml | 2 +- helm/README.md | 14 +++++ .../deployments/openshift/backup-restore.yaml | 54 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 helm/deployments/openshift/backup-restore.yaml diff --git a/helm/Chart.yaml b/helm/Chart.yaml index c7125ecaa..6186d2180 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -16,7 +16,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.1.1 +version: 2.0.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/helm/README.md b/helm/README.md index acedeb8db..a7271266f 100644 --- a/helm/README.md +++ b/helm/README.md @@ -21,3 +21,17 @@ oc project 12345-tools # step 4 - Apply deployment file oc apply -f deployments/openshift/notify-build.yaml ``` + +## Restoring from database backups +If database backups are enabled (`notify-bc.cronJob.enabled: true`), backups will be created automatically on a schedule set in `notify-bc.cronJob.schedule`. Backups are saved as date-stamped .gz (gzip) files to a PersistentVolumeClaim `...notify-bc-cronjob-mongodb-backup`. +To restore from a backup: +1. Copy your OpenShift login command and paste into a terminal. Switch to the desired project (`oc project ...`). +2. Find the `RELEASE_NAME` of the app you want to restore to. This should match the name of the PersistentVolumeClaim that contains the database backups, for example if your PVC is called `example-notifybc-dev-notify-bc-cronjob-mongodb-backup`, the `RELEASE_NAME` should be `example-notifybc-dev`. +3. Determine the `BACKUP_DATE`, the date of the backup you want to restore from. For example if you want to restore from a backup created on January 25th, 2024, the `BACKUP_DATE` should be `20240125`. + - Depending on the backup schedule there may be multiple backups performed per day in which case the latest backup from the given `BACKUP_DATE` will be used. +4. From the root of this project, run the command: + ```bash + oc process -f helm/deployments/openshift/backup-restore.yaml -p RELEASE_NAME="{RELEASE_NAME}" -p BACKUP_DATE="{BACKUP_DATE}" | oc apply -f - + ``` + (replacing `{RELEASE_NAME}` and `{BACKUP_DATE}` with the values found earlier) to run the database restore job. +5. A Job and a Pod will be created to perform the restore process which can be monitored in OpenShift. Both will be cleaned up automatically a few minutes after the process is complete. diff --git a/helm/deployments/openshift/backup-restore.yaml b/helm/deployments/openshift/backup-restore.yaml new file mode 100644 index 000000000..8908e93ac --- /dev/null +++ b/helm/deployments/openshift/backup-restore.yaml @@ -0,0 +1,54 @@ +apiVersion: template.openshift.io/v1 +kind: Template +metadata: + name: notify-bc-mongodb-restore-template +parameters: + - name: RELEASE_NAME + displayName: "Release Name" + description: "The NotifyBC release name" + required: true + - name: MONGO_IMAGE + displayName: "Mongo Image" + description: "The image used by the mongodb pods. This should match the version used by the mongodb pods." + required: true + value: "docker.io/bitnami/mongodb:7.0.4-debian-11-r0" + - name: BACKUP_DATE + displayName: "Backup Date" + description: "The date of the backup file to restore from (YYYYMMDD format, eg. 20240125)" + required: true +objects: + - apiVersion: batch/v1 + kind: Job + metadata: + name: ${RELEASE_NAME}-mongodb-restore-${BACKUP_DATE} + spec: + parallelism: 1 + completions: 1 + backoffLimit: 1 + ttlSecondsAfterFinished: 100 + template: + spec: + containers: + - name: mongodb + image: ${MONGO_IMAGE} + imagePullPolicy: IfNotPresent + volumeMounts: + - name: import + mountPath: /import + env: + - name: DATABASE_SERVICE_NAME + value: ${RELEASE_NAME}-mongodb-headless + - name: MONGODB_ADMIN_PASSWORD + valueFrom: + secretKeyRef: + name: ${RELEASE_NAME}-mongodb + key: mongodb-root-password + command: + - /bin/bash + - -vc + - mongorestore --username=root --password="$MONGODB_ADMIN_PASSWORD" --host="rs0/$DATABASE_SERVICE_NAME" --gzip --drop --archive="`find /import -name "mongodb-backup-${BACKUP_DATE}*.gz" | tail -n 1`" + restartPolicy: Never + volumes: + - name: import + persistentVolumeClaim: + claimName: ${RELEASE_NAME}-notify-bc-cronjob-mongodb-backup From 7d76c48360099435e31901ebdd4b5274fbed0cd1 Mon Sep 17 00:00:00 2001 From: Michael Haswell Date: Fri, 26 Jan 2024 10:28:15 -0800 Subject: [PATCH 2/2] Clarified arguments in command in README --- helm/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helm/README.md b/helm/README.md index a7271266f..11d2b044b 100644 --- a/helm/README.md +++ b/helm/README.md @@ -29,9 +29,9 @@ To restore from a backup: 2. Find the `RELEASE_NAME` of the app you want to restore to. This should match the name of the PersistentVolumeClaim that contains the database backups, for example if your PVC is called `example-notifybc-dev-notify-bc-cronjob-mongodb-backup`, the `RELEASE_NAME` should be `example-notifybc-dev`. 3. Determine the `BACKUP_DATE`, the date of the backup you want to restore from. For example if you want to restore from a backup created on January 25th, 2024, the `BACKUP_DATE` should be `20240125`. - Depending on the backup schedule there may be multiple backups performed per day in which case the latest backup from the given `BACKUP_DATE` will be used. -4. From the root of this project, run the command: +4. From the root of this project, run the following command: ```bash - oc process -f helm/deployments/openshift/backup-restore.yaml -p RELEASE_NAME="{RELEASE_NAME}" -p BACKUP_DATE="{BACKUP_DATE}" | oc apply -f - + oc process -f helm/deployments/openshift/backup-restore.yaml -p RELEASE_NAME="example-notifybc-dev" -p BACKUP_DATE="20240125" | oc apply -f - ``` - (replacing `{RELEASE_NAME}` and `{BACKUP_DATE}` with the values found earlier) to run the database restore job. + (replacing the example values `example-notifybc-dev` and `20240125` with the values found earlier) to run the database restore job. 5. A Job and a Pod will be created to perform the restore process which can be monitored in OpenShift. Both will be cleaned up automatically a few minutes after the process is complete.