{"id":13577279,"url":"https://github.com/ysde/grafana-backup-tool","last_synced_at":"2025-05-14T19:09:07.564Z","repository":{"id":37431167,"uuid":"58634508","full_name":"ysde/grafana-backup-tool","owner":"ysde","description":"A Python-based application to backup Grafana settings by using the Grafana API","archived":false,"fork":false,"pushed_at":"2024-07-15T12:59:54.000Z","size":309,"stargazers_count":908,"open_issues_count":68,"forks_count":282,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-05-14T19:09:04.133Z","etag":null,"topics":["backup","docker","gcs","grafana","s3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ysde.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-12T11:10:34.000Z","updated_at":"2025-04-25T21:11:47.000Z","dependencies_parsed_at":"2023-01-29T19:15:57.808Z","dependency_job_id":"d1a9ecfa-1eb4-4174-a2cc-524a2f1d82b4","html_url":"https://github.com/ysde/grafana-backup-tool","commit_stats":{"total_commits":272,"total_committers":63,"mean_commits":4.317460317460317,"dds":0.7830882352941176,"last_synced_commit":"728125dd7c7fd5309a768ff4eb6041041cd4c2e8"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysde%2Fgrafana-backup-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysde%2Fgrafana-backup-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysde%2Fgrafana-backup-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysde%2Fgrafana-backup-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ysde","download_url":"https://codeload.github.com/ysde/grafana-backup-tool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254209859,"owners_count":22032897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backup","docker","gcs","grafana","s3"],"created_at":"2024-08-01T15:01:20.077Z","updated_at":"2025-05-14T19:09:06.276Z","avatar_url":"https://github.com/ysde.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Grafana Backup Tool\n\nA Python-based application to backup Grafana settings using the [Grafana API](https://grafana.com/docs/grafana/latest/http_api/).\n\nThe aim of this tool is to:\n1. Easily backup and restore Grafana.\n2. Have versioned backups`(date and time in file name)` for restoring and saving to cloud storage providers. Currently support\n   1. `Amazon S3`\n   2. `Azure Storage`\n   3. `GCP Cloud Storage` (Use service-account's credential file, [see here](https://cloud.google.com/storage/docs/reference/libraries#linux-or-macos))\n\n## Supported components\n* Folder\n* Folder Permissions\n* Library Elements (doesn't work with Grafana 8.0.0 but 8.4.3)\n* Dashboard (contains Alert)\n* Datasource\n* Alert Channel\n* Alert Rules (Supported in version 9.4.0 of grafana and up.)\n* Teams\n* Team Members (Needs Basic Authentication (username and password, see [grafana doc](https://grafana.com/docs/grafana/latest/http_api/org/#admin-organizations-api))\n    * You need to set `Admin's account and password` in `grafanaSettings.json`, or set the base64 encoded `admin account and password` in ENV `GRAFANA_BASIC_AUTH`. E.g `export GRAFANA_BASIC_AUTH=YWRtaW46YWRtaW4=`\n    * Or Sets this ENV of the Grafana server `GF_USERS_ALLOW_ORG_CREATE=true`. see [grafana doc](https://grafana.com/docs/grafana/latest/http_api/org/#create-organization)\n* Organization (Needs Basic Authentication (username and password, see [grafana doc](https://grafana.com/docs/grafana/latest/http_api/org/#admin-organizations-api))\n    * You need to set `Admin's account and password` in `grafanaSettings.json`, or set the base64 encoded `admin account and password` in ENV `GRAFANA_BASIC_AUTH`. E.g `export GRAFANA_BASIC_AUTH=YWRtaW46YWRtaW4=`\n    * Or Sets this ENV of the Grafana server `GF_USERS_ALLOW_ORG_CREATE=true`. see [grafana doc](https://grafana.com/docs/grafana/latest/http_api/org/#create-organization)\n* User (Needs Basic Authentication (username and password, see [grafana doc](https://grafana.com/docs/grafana/latest/http_api/org/#admin-organizations-api))\n    * You need to set `Admin's account and password` in `grafanaSettings.json`, or set the base64 encoded `admin account and password` in ENV `GRAFANA_BASIC_AUTH`. E.g `export GRAFANA_BASIC_AUTH=YWRtaW46YWRtaW4=`\n    * Grafana's api doesn't provide user's password when backing up, so the `default_user_password` in `grafanaSettings.json`, or in ENV `DEFAULT_USER_PASSWORD`, E.g `export DEFAULT_USER_PASSWORD=supersecret` will be used when restoring. \n* Snapshots\n* Dashboard Versions (only backup, no restore)\n* Annotations\n\n**NOTE** The only supported `orgId` right now is `1`, the default organization will be backed up only!\n\n## Requirements\n* Bash\n* Python 2.7 or Python 3.x\n* Access to a Grafana API server.\n* A `Token` of an `Admin` role (see `Configuration` section below for more info)\n\n## Configuration\nThere are three ways to setup the configuration:\n\n1. Use `environment variables` to define the variables for connecting to a Grafana server.\n2. Use `hard-coded settings` in `conf/grafanaSettings.json` (this is the default settings file if not specified otherwise).\n3. Use `~/.grafana-backup.json` to define variables in json format.\n\n### Example Config\n* Copy [grafanaSettings.example.json](examples/grafanaSettings.example.json) and modify it for you to use, remove `azure`, `aws`, `gcp`, `influxdb` blocks (but keep the ones you used).\n* Check out the [examples](examples) folder for more configuration details.\n\n**NOTE** If you use `environment variables`, you need to add the following to your `.bashrc` or execute once before using the tool (please change variables according to your setup):\n\n(`GRAFANA_HEADERS` is optional, use it if necessary. please see [#45](https://github.com/ysde/grafana-backup-tool/issues/45))\n\n```bash\n### Do not use a trailing slash on GRAFANA_URL\nexport GRAFANA_URL=http://some.host.org:3000\nexport GRAFANA_TOKEN=eyJrIjoidUhaU2ZQQndrWFN3RRVkUnVfrT56a1JoaG9KWFFObEgiLCJuIjoiYWRtaW4iLCJpZCI6MX0=\n\n# GRAFANA_HEADERS is optional\nexport GRAFANA_HEADERS=Host:some.host.org\n```\n\nTo create and obtain a `Token` for your Grafana server, please refer to the [official documentation](https://grafana.com/docs/grafana/latest/http_api/auth/).\n\n**NOTE** that you need to generate a `Token` with an `Admin` role for the backup to succeed, otherwise you will have potential permission issues.\n\n## Installation\n### Virtual environment (optional but recommended)\nCreate a virtualenv, you could using something like `pyenv` if you'd prefer\n```\nvirtualenv -p $(which python3) venv\nsource venv/bin/activate\n```\n\n### Installation using pypi\n```\npip install grafana-backup\n```\n\n### Installation using this repo\nFirst clone this repo\n```\ngit clone https://github.com/ysde/grafana-backup-tool.git\ncd grafana-backup-tool\n```\nInstallation works best using `pip`\n```\npip install .\n```\n\n## How to Use\n* First perform the **Configuration** and **Installation** sections as described above.\n* Use the `grafana-backup save` command to backup all your folders, dashboards, datasources and alert channels to the `_OUTPUT_` subdirectory of the current directory.\n\n***Example:***\n\n```bash\n$ grafana-backup save\n$ tree _OUTPUT_\n_OUTPUT_/\n└── 202006272027.tar.gz\n```\n\n* Use the `grafana-backup restore \u003carchive_file\u003e` command with a path to a previous backup to restore everything.\n\n**NOTE** this *may* result in data loss, by overwriting data on the server.\n\n***Example:***\n\n```bash\n$ grafana-backup restore _OUTPUT_/202006272027.tar.gz\n```\n\n## Docker\nReplace variables below to use the Docker version of this tool\n* `{YOUR_GRAFANA_TOKEN}`: Your Grafana site `Token`.\n* `{YOUR_GRAFANA_URL}`: Your Grafana site `URL`.\n* `{YOUR_BACKUP_FOLDER_ON_THE_HOST}`: The `backup folder` on the Grafana host machine.\n\n## Kubernetes\nCheck out the CronJob in [examples](examples) for a simple example of how grafana-backup-tool\ncan be ran within a Kubernetes environment\n\n### Backup\n\nIf you decide to use a volume (-v) then you'll need to create the volume first with 1337 uid/gid ownership first, example:\n```\nmkdir /tmp/backup\nsudo chown 1337:1337 /tmp/backup\n```\n\n```\ndocker run --user $(id -u):$(id -g) --rm --name grafana-backup-tool \\\n           -e GRAFANA_TOKEN={YOUR_GRAFANA_TOKEN} \\\n           -e GRAFANA_URL={YOUR_GRAFANA_URL} \\\n           -e GRAFANA_ADMIN_ACCOUNT={YOUR_GRAFANA_ADMIN_ACCOUNT} \\\n           -e GRAFANA_ADMIN_PASSWORD={YOUR_GRAFANA_ADMIN_PASSWORD} \\\n           -e VERIFY_SSL={True/False} \\\n           -v {YOUR_BACKUP_FOLDER_ON_THE_HOST}:/opt/grafana-backup-tool/_OUTPUT_  \\\n           ysde/docker-grafana-backup-tool\n```\n\n***Example:***\n\n```\ndocker run --user $(id -u):$(id -g) --rm --name grafana-backup-tool \\\n           -e GRAFANA_TOKEN=\"eyJrIjoiNGZqTDEyeXNaY0RsMXNhbkNTSnlKN2M3bE1VeHdqVTEiLCJuIjoiZ3JhZmFuYS1iYWNrdXAiLCJpZCI6MX0=\" \\\n           -e GRAFANA_URL=http://192.168.0.79:3000 \\\n           -e GRAFANA_ADMIN_ACCOUNT=admin \\\n           -e GRAFANA_ADMIN_PASSWORD=adminpassword \\\n           -e VERIFY_SSL=False \\\n           -v /tmp/backup/:/opt/grafana-backup-tool/_OUTPUT_ \\\n           ysde/docker-grafana-backup-tool\n```\n\n***S3 Example:*** Set S3 configurations in `-e` or `grafanaSettings.json`([example](https://github.com/ysde/grafana-backup-tool/blob/master/examples/grafana-backup.example.json))\n```\n           -e AWS_S3_BUCKET_NAME=\"my-backups-bucket\" \\\n           -e AWS_S3_BUCKET_KEY=\"grafana-backup-folder\" \\\n           -e AWS_DEFAULT_REGION=\"us-east-1\" \\\n           -e AWS_ACCESS_KEY_ID=\"secret\" \\\n           -e AWS_SECRET_ACCESS_KEY=\"secret\" \\\n```\n\n***Azure Example:*** Set Azure configurations in `-e` or `grafanaSettings.json`([example](https://github.com/ysde/grafana-backup-tool/blob/master/examples/grafana-backup.example.json))\n```\n\t\t   -e AZURE_STORAGE_CONTAINER_NAME=\"azure-storage-container-name\" \\\n\t\t   -e AZURE_STORAGE_CONNECTION_STRING=\"azure-storage-connection-string\"\n```\n\n***GCS Example:*** Set GCS configurations in `-e` or `grafanaSettings.json`([example](https://github.com/ysde/grafana-backup-tool/blob/master/examples/grafana-backup.example.json))\n```\n\t\t   -e GCS_BUCKET_NAME=\"backups-bucket-name\" \\\n\t\t   -e GCS_BUCKET_PATH=\"grafana-backup-folder\" \\\n\t\t   -e GCLOUD_PROJECT=\"gcp-project-name\" \\\n\t\t   -e GOOGLE_APPLICATION_CREDENTIALS=\"credential-file-path\"\n```\n\n\n### Restore\n\n```\ndocker run --user $(id -u):$(id -g) --rm --name grafana-backup-tool \\\n           -e GRAFANA_TOKEN={YOUR_GRAFANA_TOKEN} \\\n           -e GRAFANA_URL={YOUR_GRAFANA_URL} \\\n           -e GRAFANA_ADMIN_ACCOUNT={YOUR_GRAFANA_ADMIN_ACCOUNT} \\\n           -e GRAFANA_ADMIN_PASSWORD={YOUR_GRAFANA_ADMIN_PASSWORD} \\\n           -e VERIFY_SSL={True/False} \\\n           -e RESTORE=\"true\" \\\n           -e ARCHIVE_FILE={THE_ARCHIVED_FILE_NAME} \\\n           -v {YOUR_BACKUP_FOLDER_ON_THE_HOST}:/opt/grafana-backup-tool/_OUTPUT_  \\\n           ysde/docker-grafana-backup-tool\n```\n\n***Example:***\n\n```\ndocker run --user $(id -u):$(id -g) --rm --name grafana-backup-tool \\\n           -e GRAFANA_TOKEN=\"eyJrIjoiNGZqTDEyeXNaY0RsMXNhbkNTSnlKN2M3bE1VeHdqVTEiLCJuIjoiZ3JhZmFuYS1iYWNrdXAiLCJpZCI6MX0=\" \\\n           -e GRAFANA_URL=http://192.168.0.79:3000 \\\n           -e GRAFANA_ADMIN_ACCOUNT=admin \\\n           -e GRAFANA_ADMIN_PASSWORD=adminpassword \\\n           -e VERIFY_SSL=False \\\n           -e RESTORE=\"true\" \\\n           -e ARCHIVE_FILE=\"202006280247.tar.gz\" \\\n           -v /tmp/backup/:/opt/grafana-backup-tool/_OUTPUT_ \\\n           ysde/docker-grafana-backup-tool\n```\n\n### Building\nYou can build the docker image simply by executing `make` in the root of this repo. The image will get tagged as `ysde:grafana-backup`\n\n### Monitoring\nInfluxDB support has been added and Prometheus push gateway support will be added in the future.\n\nIn order to monitor successful backups with InfluxDB simply configure `grafana-backup` InfluxDB settings using this [example](examples) configuration.\nOr if you prefer to use environment variables you can instead set `INFLUXDB_HOST`, `INFLUXDB_PORT`, `INFLUXDB_MEASUREMENT`, `INFLUXDB_USERNAME` and `INFLUXDB_PASSWORD`.\n\nOnce configured `grafana-backup` will automatically enter a `1` in your defined timeseries measurement upon each successful backup.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysde%2Fgrafana-backup-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fysde%2Fgrafana-backup-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysde%2Fgrafana-backup-tool/lists"}