|
| 1 | +--- |
| 2 | +title: 'Back up Grafana' |
| 3 | +date: '2023-10-18T11:01:56-03:00' |
| 4 | +categories: ["how-to"] |
| 5 | +description: How to backup Grafana on your Rhize deployment |
| 6 | +weight: 300 |
| 7 | +--- |
| 8 | + |
| 9 | +This guide shows you the procedure to back up Grafana on your Rhize Kubernetes deployment. |
| 10 | +For general instructions, refer to the official [Back up Grafana](https://grafana.com/docs/grafana/latest/administration/back-up-grafana/) documentation. |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +Before you start, ensure you have the following: |
| 15 | + |
| 16 | +- A designated backup location, for example `~/rhize-backups/grafana`. |
| 17 | +- Access to the [Rhize Kubernetes Environment](/deploy/install/setup-kubernetes) |
| 18 | +{{% param pre_reqs %}} |
| 19 | + |
| 20 | + |
| 21 | +Also, before you start, confirm you are in the right context and namespace. |
| 22 | + |
| 23 | +{{% param k8s_cluster_ns %}} |
| 24 | + |
| 25 | +## Steps |
| 26 | + |
| 27 | +To back up the Grafana, follow these steps: |
| 28 | + |
| 29 | +1. Check the logs for the Grafana pods, either in Lens or with [`kubectl logs`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#logs). |
| 30 | + Ensure there are no errors. |
| 31 | + |
| 32 | +1. Open a pod shell for one of the Grafana pods: |
| 33 | + |
| 34 | + ```bash |
| 35 | + kubectl exec --stdin --tty <GRAFANA_POD_NAME> -- /bin/bash |
| 36 | + ``` |
| 37 | + |
| 38 | + For details, read the Kubernetes topic [Get Shell to a Running Container](https://kubernetes.io/docs/tasks/debug/debug-application/get-shell-running-container/). |
| 39 | + |
| 40 | +1. Use `tar` to backup the Grafana data and `conf` directories: |
| 41 | + |
| 42 | + ```bash |
| 43 | + ## Data Directory Backup Command |
| 44 | + tar -v -c -f /home/grafana/grafana-data-$(date +"%Y-%m-%dT%H.%M.%S").tar.gz /var/lib/grafana |
| 45 | + ## Conf Directory Backup Command |
| 46 | + tar -v -c -f /home/grafana/grafana-conf-$(date +"%Y-%m-%dT%H.%M.%S").tar.gz /usr/share/grafana/conf |
| 47 | + ``` |
| 48 | + |
| 49 | +1. Change to the backup directory. For example: |
| 50 | + |
| 51 | + ```bash |
| 52 | + cd /home/grafana/ |
| 53 | + ``` |
| 54 | + |
| 55 | +1. Check for the latest `.gz` files (for example, with `ls -lt`). |
| 56 | + There should be new backup `data` and `conf` files whose names include timestamps from when you ran the preceding `tar` commands. |
| 57 | + |
| 58 | +1. Create a checksum file for the latest backups: |
| 59 | + |
| 60 | + ```bash |
| 61 | + sha256sum <LATEST_DATA_FILE>.tar.gz <LATEST_CONF_FILE>.tar.gz > backup.sums |
| 62 | + ``` |
| 63 | + |
| 64 | + |
| 65 | +1. Exit the container shell, and then copy files out of the container to your backup location: |
| 66 | + |
| 67 | + ```bash |
| 68 | + ## exit shell |
| 69 | + exit |
| 70 | + ## copy container files to backup |
| 71 | + kubectl cp <GRAFANA_POD>:/home/grafana/<NEW_DATA_BACKUP_FILENAME> \ |
| 72 | + ./<NEW_DATA_BACKUP_FILENAME> -c grafana |
| 73 | +
|
| 74 | + kubectl cp <GRAFANA_POD>:/home/grafana/<NEW_CONF_BACKUP_FILENAME> \ |
| 75 | + ./<NEW_CONF_BACKUP_FILENAME> -c grafana |
| 76 | + kubectl cp <GRAFANA_POD>:/home/grafana/backup.sums \ |
| 77 | + ./backup.sums -c grafana |
| 78 | + ``` |
| 79 | + |
| 80 | +## Confirm success |
| 81 | + |
| 82 | + |
| 83 | +To confirm the backup, check their sha256 sums and their content. |
| 84 | + |
| 85 | +To check the sums: |
| 86 | + |
| 87 | +1. Change to the directory where you sent the backups: |
| 88 | + |
| 89 | + ```bash |
| 90 | + cd <BACKUP>/<ON_YOUR_DEVICE>/ |
| 91 | + ``` |
| 92 | + |
| 93 | +1. Confirm the checksums match: |
| 94 | + |
| 95 | + ```bash |
| 96 | + sha256sum -c backup.sums \ |
| 97 | + <LATEST_DATA_FILE>.tar.gz <LATEST_CONF_FILE>.tar.gz |
| 98 | + ``` |
| 99 | + |
| 100 | +To check that the content is correct, unzip the files and inspect the data. |
| 101 | + |
| 102 | +## Next steps |
| 103 | + |
| 104 | +- Test the [Restore Grafana]({{< relref "../restore" >}}) procedure to ensure you can recover data in case of an emergency. |
| 105 | +- To back up other Rhize services, read how to backup [the Graph Database]({{< relref "graphdb" >}}). |
0 commit comments