「Grafana」- 备份 | grafana-backup-tool

认识

官网:None
文档:None
仓库:https://github.com/ysde/grafana-backup-tool

构建

pip install grafana-backup

# Create an API Token
curl -X POST -H "Content-Type: application/json"           \
    -d '{"name":"apikeycurl", "role": "Admin"}'            \
    https://admin:admin@grafana.example.com/api/auth/keys

export GRAFANA_URL=https://grafana.example.com
export GRAFANA_TOKEN=eyJrIjoib1NHQlhIYUtIY1B5ak0y...

~/.local/bin/grafana-backup save

~/.local/bin/grafana-backup restore _OUTPUT_/202307061639.tar.gz

关于 GRAFANA_TOKEN 参数:
1)在早期版本中,能够通过 Web 界面获取;
2)在 Grafana v10.0.1 中,我们需要通过 Web API 获取:API Tutorial: Create API tokens and dashboards for an organization

改进

… grafana auth check … 404 … {‘message’: ‘Not found’} …

# grafana-backup --config ./.grafana-backup.json restore _OUTPUT_/202402221810.tar.gz

[Pre-Check] grafana health check: https://grafana.infr.yuyidigi.com/api/health
[DEBUG] resp status: 200
[DEBUG] resp body: {'database': 'ok', 'version': '12.2.1', 'commit': '563109b696e9c1cbaf345f2ab7a11f7f78422982'}

[Pre-Check] grafana auth check: https://grafana.infr.yuyidigi.com/api/auth/keys
[DEBUG] resp status: 404
[DEBUG] resp body: {'message': 'Not found'}
Traceback (most recent call last):
  File "/home/k4nzdroid/.asdf/installs/python/3.12.10/bin/grafana-backup", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/k4nzdroid/.asdf/installs/python/3.12.10/lib/python3.12/site-packages/grafana_backup/cli.py", line 55, in main
    restore(args, settings)
  File "/home/k4nzdroid/.asdf/installs/python/3.12.10/lib/python3.12/site-packages/grafana_backup/restore.py", line 44, in main
    (status, json_resp, dashboard_uid_support, datasource_uid_support,
ValueError: not enough values to unpack (expected 6, got 5)

2025-11-18 通过 .grafana-backup.json “api_auth_check”: false 解决。

参考

ysde/grafana-backup-tool: A Python-based application to backup Grafana settings by using the Grafana API