Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created backup-restore.yaml Job Template to make restoring from a bac… #11

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Creating new versions of this chart
1. Update the `version` property in `helm/Chart.yaml` to the desired version number.
2. From the `helm/` directory, run the command `helm package ./` to create a `.tgz` package for the new version.
3. Move the new `.tgz` file to the `docs/` directory (`mv notify-bc-[version].tgz ../docs/helm`).
4. Update `docs/helm/index.yaml` to list the new package (`helm repo index ../docs/helm`).

## Deploying to OpenShift
1. In this example we will be deploying to `dev`, so a file named `values.dev.local.yaml` should exist and contain values specific to the `dev` instance.
1. Run `helm install dev -f platform-specific/openshift.yaml -f values.yaml -f values.dev.local.yaml ./`
- If a deployment already exists, run `helm uninstall dev` to remove it, then repeat the command above.
1. To deploy to `test`, replace `dev` with `test` in the above example.

## Deploying BuildConfig and ImageStream for NotifyBC application
```bash
# Step 1 - Go to helm/ directory of repo
cd helm
# Step 2 - Login to OpenShift oc command line
oc login --token=secret-token --server=https://myopnshift.com
# Step 3 - Choose the tools folder
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.
54 changes: 54 additions & 0 deletions helm/deployments/openshift/backup-restore.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading