Restore a vFunction Server in an OpenShift Cluster



Overview

In some OpenShift environments, the Cluster may be repaved at regular intervals. The following steps can be taken to restore a vFunction Server after the Cluster / Namespace has been deleted.


Prerequisites

  • A valid MySQL DB Dump to use as a restoration source. These are kept on the MySQL Persistent Volume and can be retrieved from /opt/vfunction/backup/ on that Volume
  • Same vFunction Server major version as the MySQL DB Dump, e.g v3.5

Install a new vFunction Server

  1. In the OperatorHub, create a new instance of the vFunction Server. Use the same values in the Installation.yaml that were used in the previous Server
  2. If possible, use the same DB and Storage PersistentVolumes as in the previous Server
  3. Wait for the installation to complete and for all Pods to come up healthy

Restore the Keys from the original vFunction Server

  1. Copy the MySQL DB Dump to a temporary folder
  2. Extract the DB Dump
  3. Retrieve the CLIENT_ID, CLIENT_SECRET, APP_CLIENT_ID, and APP_CLIENT_SECRET
### Find-and-replace the string <sql-dump-file>

CLIENT_ID=$(grep "INSERT INTO \`client\` VALUES" <sql-dump-file> | cut -d\( -f2 | cut -d, -f1 | sed "s~'~~g")

CLIENT_SECRET=$(grep "INSERT INTO \`client\` VALUES" <sql-dump-file> | cut -d\( -f2 | cut -d, -f2 | sed "s~'~~g")

APP_CLIENT_ID=$(grep "INSERT INTO \`client\` VALUES" <sql-dump-file> | cut -d\( -f3 | cut -d, -f1 | sed "s~'~~g")

APP_CLIENT_SECRET=$(grep "INSERT INTO \`client\` VALUES" <sql-dump-file> | cut -d\( -f3 | cut -d, -f2 | sed "s~'~~g")

Add the original Keys into the new vFunction Server

Use the OpenShift Command Line Tool, OC, to modify the configMaps of the new Server to add in the values from the original vFunction Server.

### Find-and-replace the string, <namespace>

NAMESPACE=<namespace>

identifier=$(oc get configmap -n $NAMESPACE | grep nginx-custom-env | cut -d' ' -f1 | cut -d- -f4)

oc patch configmap vfapi-custom-env.list-$identifier -n $NAMESPACE --type merge -p "{\"data\":{\"CLIENT_ID\":\"$CLIENT_ID\", \"CLIENT_SECRET\":\"$CLIENT_SECRET\"}}"               

### Do not run this command below if the environment uses OpenID for Authentication
oc patch configmap nginx-custom-env.list-$identifier -n $NAMESPACE --type merge -p "{\"data\":{\"CLIENT_ID\":\"$APP_CLIENT_ID\", \"CLIENT_SECRET\":\"$APP_CLIENT_SECRET\"}}"

oc patch configmap nginx-custom-env.list-$identifier -n $NAMESPACE --type merge -p "{\"data\":{\"GENERATED_CLIENT_ID\":\"$APP_CLIENT_ID\", \"GENERATED_CLIENT_SECRET\":\"$APP_CLIENT_SECRET\"}}"

Restore the MySQL DB from the Backup

  1. Go inside vfunction-mysql-xxx pod
  2. Locate the desired dump under /opt/vfunction/backup/ or copy it there
  3. Restore the DB
### Find-and-replace <dump> with the Archived filename

/usr/share/container-scripts/mysql/backup.sh restore <dump>

Restart all Pods

You can delete the Deployments from the OpenShift Console, or take the following steps using the OpenShift Command Line Tool, oc:

### Note that the variables $identifier and $NAMESPACE were created in
### the section, "Add the original Keys into the new vFunction Server"

oc delete vfunction-mysql-$identifier -n $NAMESPACE
oc delete vfunction-vfapi-idp-$identifier -n $NAMESPACE
oc delete vfunction-vfapi-measurements-$identifier -n $NAMESPACE
oc delete vfunction-vfapi-organizations-$identifier -n $NAMESPACE
oc delete vfunction-vfapi-parser-$identifier -n $NAMESPACE
oc delete vfunction-vfapi-users-$identifier -n $NAMESPACE
oc delete vfunction-nginx-$identifier -n $NAMESPACE

Wait for the vFunction OpenShift Operator to bring back up all pods, and the site will be up with the original vFunction Server data.