Edit Page

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:

Steps

  1. Confirm the cluster and namespace are correct.

    ## context
    kubectl config current-context
    ## namespace
    kubectl get namespace
    

    To change the namespace for all subsequent kubectl commands to libre, run this command:

    kubectl config set-context --current --namespace=libre
    

    For a reference of useful kubectl commands, refer to the official kubectl Cheat Sheet.

  2. Change to the libre-baas helm chart overrides, baas.yaml. Set alpha.initContainers.init.enable to true.

  3. Upgrade or install the Helm chart.

    helm upgrade --install -f baas.yaml libre-baas libre/baas -n libre
    
  4. In the Alpha 0 initialization container, create the backup directory.

    kubectl exec -t libre-baas-alpha-0 -c libre-baas-alpha-init -- \
    mkdir -p /dgraph/backups
    
  5. If the backup directory does not have a checksums file, create one.

    sha256sum ./<PATH_TO_BACKUP>/*.gz > ./<PATH_TO_BACKUP>/backup.sums
    
  6. Copy 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-init
    

    After 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'
    
  7. 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_out
    
  8. Copy the backup to the correct directory:

    kubectl exec -t libre-baas-alpha-0 -c libre-baas-alpha-init -- \
    mv /dgraph/restore/0/p /dgraph/p
    
  9. Complete the initialization container for alpha 0.

    kubectl exec -t libre-baas-alpha-0 -c libre-baas-alpha-init -- touch /dgraph/doneinit
    
  10. Wait for libre-baas-alpha-0 to start serving the GraphQL API.

  11. Make a database mutation to force a snapshot to be taken. For example, create a UnitOfMeasure then 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: 9
    

    Revert 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"}]}}'
    
  12. Complete the initialization container for alpha 1:

    kubectl exec -t libre-baas-alpha-1 -c libre-baas-alpha-init -- \
    touch /dgraph/doneinit
    

    And alpha 2:

    kubectl exec -t libre-baas-alpha-2 -c libre-baas-alpha-init -- \
    touch /dgraph/doneinit