Restore the GraphDB
This guide shows you how to restore the Graph database in your Rhize environment.
Prerequisites
Before you start, ensure you have the following:
- The GraphDB Helm chart
kubectl- A Database backup
Steps
Confirm the cluster and namespace are correct.
## context kubectl config current-context ## namespace kubectl get namespaceTo change the namespace for all subsequent
kubectlcommands tolibre, run this command:kubectl config set-context --current --namespace=libreFor a reference of useful
kubectlcommands, refer to the official kubectl Cheat Sheet.Change to the libre-baas helm chart overrides,
baas.yaml. Setalpha.initContainers.init.enabletotrue.Upgrade or install the Helm chart.
helm upgrade --install -f baas.yaml libre-baas libre/baas -n libreIn the Alpha 0 initialization container, create the backup directory.
kubectl exec -t libre-baas-alpha-0 -c libre-baas-alpha-init -- \ mkdir -p /dgraph/backupsIf the backup directory does not have a checksums file, create one.
sha256sum ./<PATH_TO_BACKUP>/*.gz > ./<PATH_TO_BACKUP>/backup.sumsCopy the backup into the initialization container.
kubectl cp --retries=10 ./<PATH_TO_BACKUP> \ libre-baas-alpha-0:/dgraph/backups/<PATH_TO_BACKUP> \ -c libre-baas-alpha-initAfter the process finishes, confirm that the checksums match:
kubectl exec -it libre-baas-alpha-0 -c libre-baas-alpha-init -- \ 'sha256sum -c /dgraph/backups/<PATH_TO_BACKUP>/backup.sums /dgraph/backups/<PATH_TO_BACKUP>/*.gz'Restore the backup to the restore directory. Replace the
<PATH_TO_BACKUP>and<NAMESPACE>in the arguments for the following command:kubectl exec -t libre-baas-alpha-0 -c libre-baas-alpha-init -- \ dgraph bulk -f /dgraph/backups/<PATH_TO_BACKUP>/g01.json.gz \ -g /dgraph/backups/<PATH_TO_BACKUP>/g01.gql_schema.gz \ -s /dgraph/backups/<PATH_TO_BACKUP>/g01.schema.gz \ --zero=libre-baas-zero-0.libre-baas-zero-headless.<NAMESPACE>.svc.cluster.local:5080 \ --out /dgraph/restore --replace_outCopy the backup to the correct directory:
kubectl exec -t libre-baas-alpha-0 -c libre-baas-alpha-init -- \ mv /dgraph/restore/0/p /dgraph/pComplete the initialization container for alpha 0.
kubectl exec -t libre-baas-alpha-0 -c libre-baas-alpha-init -- touch /dgraph/doneinitWait for
libre-baas-alpha-0to start serving the GraphQL API.Make a database mutation to force a snapshot to be taken. For example, create a
UnitOfMeasurethen delete it:kubectl exec -t libre-baas-alpha-0 -c libre-baas-alpha -- \ curl --location --request POST 'http://localhost:8080/graphql' \ --header 'Content-Type: application/json' \ --data-raw '{"query":"mutation RestoringDatabase($input:[AddUnitOfMeasureInput!]!){\r\n addUnitOfMeasure(input:$input){\r\n unitOfMeasure{\r\n id\r\n dataType\r\n code\r\n }\r\n}\r\n}","variables":{"input":[{"code":"Restoring","isActive":true,"dataType":"BOOL"}]}}'Wait until you see libre-baas creating a snapshot in the logs. For example:
$ kubectl logs libre-baas-alpha-0 ++ hostname -f ++ awk '{gsub(/\.$/,""); print $0}' ... I0314 20:32:21.282271 19 draft.go:805] Creating snapshot at Index: 16, ReadTs: 9Revert any database mutations:
kubectl exec -t libre-baas-alpha-0 -c libre-baas-alpha -- \ curl --location --request POST 'http://localhost:8080/graphql' \ --header 'Content-Type: application/json' \ --data-raw '{"query":"mutation {\r\n deleteUnitOfMeasure(filter:{code:{eq:\"Restoring\"}}){\r\n unitOfMeasure{\r\n id\r\n }\r\n }\r\n}","variables":{"input":[{"code":"Restoring","isActive":true,"dataType":"BOOL"}]}}'Complete the initialization container for alpha 1:
kubectl exec -t libre-baas-alpha-1 -c libre-baas-alpha-init -- \ touch /dgraph/doneinitAnd alpha 2:
kubectl exec -t libre-baas-alpha-2 -c libre-baas-alpha-init -- \ touch /dgraph/doneinit