Edit Page

Back up Grafana

This guide shows you the procedure to back up Grafana on your Rhize Kubernetes deployment. For general instructions, refer to the official Back up Grafana documentation.

Prerequisites

Before you start, ensure you have the following:

  • A designated backup location, for example ~/rhize-backups/grafana.
  • Access to the Rhize Kubernetes Environment
  • Optional: kubectx utilities
    • kubectx to manage multiple clusters
    • kubens to switch between and configure namespaces easily
  • Optional: the k8 Lens IDE, if you prefer to use Kubernetes graphically

Also, before you start, confirm you are in the right context and namespace.

## 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.

Steps

To back up the Grafana, follow these steps:

  1. Check the logs for the Grafana pods, either in Lens or with kubectl logs. Ensure there are no errors.

  2. Open a pod shell for one of the Grafana pods:

    kubectl exec --stdin --tty <GRAFANA_POD_NAME> -- /bin/bash
    

    For details, read the Kubernetes topic Get Shell to a Running Container.

  3. Use tar to backup the Grafana data and conf directories:

    ## Data Directory Backup Command
    tar -v -c -f /home/grafana/grafana-data-$(date +"%Y-%m-%dT%H.%M.%S").tar.gz /var/lib/grafana
    ## Conf Directory Backup Command
    tar -v -c -f /home/grafana/grafana-conf-$(date +"%Y-%m-%dT%H.%M.%S").tar.gz /usr/share/grafana/conf
    
  4. Change to the backup directory. For example:

    cd /home/grafana/
    
  5. Check for the latest .gz files (for example, with ls -lt). There should be new backup data and conf files whose names include timestamps from when you ran the preceding tar commands.

  6. Create a checksum file for the latest backups:

    sha256sum <LATEST_DATA_FILE>.tar.gz <LATEST_CONF_FILE>.tar.gz > backup.sums
    
  7. Exit the container shell, and then copy files out of the container to your backup location:

    ## exit shell
    exit
    ## copy container files to backup
    kubectl cp <GRAFANA_POD>:/home/grafana/<NEW_DATA_BACKUP_FILENAME> \
    ./<NEW_DATA_BACKUP_FILENAME> -c grafana
    
    kubectl cp <GRAFANA_POD>:/home/grafana/<NEW_CONF_BACKUP_FILENAME> \
    ./<NEW_CONF_BACKUP_FILENAME> -c grafana
    kubectl cp <GRAFANA_POD>:/home/grafana/backup.sums \
    ./backup.sums -c grafana
    

Confirm success

To confirm the backup, check their sha256 sums and their content.

To check the sums:

  1. Change to the directory where you sent the backups:

    cd <BACKUP>/<ON_YOUR_DEVICE>/
    
  2. Confirm the checksums match:

    sha256sum -c backup.sums \
    <LATEST_DATA_FILE>.tar.gz <LATEST_CONF_FILE>.tar.gz
    

To check that the content is correct, unzip the files and inspect the data.

Next steps