Get icon
Script icon
If icon
PushExecutionFiles icon
SlackIncomingWebhook icon
Set icon
Schedule icon

Back Up Grafana Dashboards to Git and Post What Changed

Export every Grafana dashboard nightly, commit the JSON to a Git repository by folder and post a Slack summary of added, changed and deleted dashboards.

Categories
CoreInfrastructure

Grafana dashboards are usually edited in the UI, and the history Grafana keeps disappears with the instance, a bad migration or a dashboard someone deleted. This blueprint gives them a real history: every night it exports every dashboard through the Grafana HTTP API, writes one JSON file per dashboard grouped by folder, commits the result to a Git repository and posts to Slack which dashboards were added, changed or deleted.

How it works

  1. load_hashes reads the content hash of every dashboard file at the last backup from the Kestra KV store.
  2. export_dashboards lists dashboards with /api/search, downloads each model with /api/dashboards/uid/<uid>, removes the id and version fields that change on every save, and writes sorted JSON to <folder>/<uid>.json. Comparing hashes tells it which dashboards were added, changed or removed.
  3. if_changed stops here when nothing changed: no empty commits, no message.
  4. push (PushExecutionFiles) commits the files under path in the backup repository. With delete: true, files of dashboards deleted in Grafana are removed from the branch and stay in the Git history.
  5. notify posts the added, changed and deleted dashboards to Slack.
  6. remember_hashes stores the hashes after the push, so a failed push is retried.

The errors branch posts to Slack when Grafana or Git cannot be reached.

To restore a dashboard, import its JSON file in Grafana (Dashboards, New, Import) or POST it to /api/dashboards/db.

Prerequisites

  • A Grafana service account token with the Viewer role. Folder permissions decide which dashboards it can see.
  • A Git repository for the backups and a token that can push to it. The branch is created if it does not exist.
  • A Slack Incoming Webhook.

Secrets

  • GRAFANA_TOKEN: Grafana service account token.
  • GIT_USERNAME and GIT_TOKEN: Git credentials. For GitHub, use your username and a fine-grained token with Contents: Read and write on the backup repository.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for summaries and failures.

In the open-source edition, secrets are environment variables on the Kestra container, prefixed with SECRET_ and base64-encoded. See how to manage secrets.

Inputs

  • grafana_url (STRING): the Grafana base URL.
  • git_url (STRING), branch (STRING, default main) and path (STRING, default dashboards): where the backups are committed.

Quick start

  1. Create the service account token and the backup repository, and add the secrets.
  2. Set grafana_url and git_url, and execute the flow: every dashboard is committed and reported as added.
  3. Edit a dashboard in Grafana and execute it again: one commit with only that dashboard, and a Slack message naming it.
  4. Enable nightly.

Outputs

  • {{ outputs.export_dashboards.vars }}: total, added, changed, removed.
  • A commit in the backup repository whenever a dashboard changed.
  • KV entry grafana_backup_<grafana_url>: the hash and title of every backed-up dashboard.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.