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 clusterskubens
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:
Check the logs for the Grafana pods, either in Lens or with
kubectl logs
. Ensure there are no errors.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.
Use
tar
to backup the Grafana data andconf
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
Change to the backup directory. For example:
cd /home/grafana/
Check for the latest
.gz
files (for example, withls -lt
). There should be new backupdata
andconf
files whose names include timestamps from when you ran the precedingtar
commands.Create a checksum file for the latest backups:
sha256sum <LATEST_DATA_FILE>.tar.gz <LATEST_CONF_FILE>.tar.gz > backup.sums
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:
Change to the directory where you sent the backups:
cd <BACKUP>/<ON_YOUR_DEVICE>/
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
- Test the Restore Grafana procedure to ensure you can recover data in case of an emergency.
- To back up other Rhize services, read how to backup the Graph Database.