Skip to content

Python codes to dump or create dashboards and datasources from Grafana using it's API

Notifications You must be signed in to change notification settings

swisscom-bigdata/grafana-backup-tool

 
 

Repository files navigation

Grafana Dashboard Backup Tool

Some python programs to call Grafana API to:

  • Save every datasource to each datasource file.
    • saveDatasources.py
  • Save every folder to each datasource file.
    • saveFolders.py
  • Save every dashboard to each dashboard file.
    • saveDashboards.py
  • Create datasource from a backup file.
    • createDatasource.py
  • Create dashboard from a backup file.
    • createDashboard.py
  • Create folder from a backup file. (supported from Grafana v.5.0.*)
    • createFolder.py

There a three convenient script files:

  1. backup_grafana.sh
  2. restore_dashboards.sh
  3. restore_datasources.sh
  4. restore_folders.sh

you can use them to

  1. backup all datasources, dashboards and folders.
  • ex: sh backup_grafana.sh
  1. restore dashboards from your dashboard backup folder.
  • ex: sh restore_dashboards.sh /tmp/dashboards/2016-10-10_12:00:00
  1. restore datasources from your datasource backup folder.
  • ex: sh restore_dashboards.sh /tmp/datasources/2016-10-10_12:00:00
  1. restore folders from your folder backup folder.
  • ex: sh restore_folders.sh /tmp/folders/2016-10-10_12:00:00

Grafana API document

ENV:

  • python 2.7
    • Need to pip install requests library
  • Garafana 3.0 API

Setting

  1. Export the environment variables bellow
  2. GRAFANA_URL (the default url is http://localhost:3000)
  3. GRAFANA_TOKEN

You can see how to get token from here: Grafana Web page

How to Use

  • First edit grafana_settings.py as above.

  • Use saveDashboards.py to save each dashboard to each file.

    • ex: python saveDashboards.py folder_path
  • Use saveDatasources.py to save each datasources to each file under specific folder.

    • ex: python saveDatasources.py folder_path
  • Use saveFolders.py to save each folders to each file under specific folder.

    • ex: python saveFolders.py folder_path
  • Use createDashboard.py to read the dashboard file and create or update them on Grafana.

    • ex: python createDashboard.py file_path
  • Use createDatasource.py to read the datasource file and create or update them on Grafana.

    • ex: python createDatasource.py file_path
  • Use createFolder.py to read the folder file and create or update them on Grafana.

    • ex: python createFolder.py file_path
  • Use backup_grafana.sh to backup all your dashboards, datasources and folders to /tmp folder.

    • It will create
      • three files: /tmp/dashboards.tar.gz, /tmp/datasources.tar.gz and /tmp/folders.tar.gz
      • three folders contain dashboard files, datasource files and folders file: /tmp/dashboards/$current_time, /tmp/datasources/$current_time and /tmp/folders/$current_time
    • ex:sh backup_grafana.sh
    • result:/tmp/dashboads.tar.gz, /tmp/datasourcess.tar.gz, /tmp/folders.tar.gz, /tmp/dashboards/2016-10-10_12:00:00, /tmp/datasources/2016-10-10_12:00:00, /tmp/folders/2016-10-10_12:00:00

About

Python codes to dump or create dashboards and datasources from Grafana using it's API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 83.2%
  • Shell 16.8%