{"id":13585052,"url":"https://github.com/molu8bits/grafana-migration-tool","last_synced_at":"2025-03-16T21:18:08.894Z","repository":{"id":177955934,"uuid":"182146735","full_name":"molu8bits/grafana-migration-tool","owner":"molu8bits","description":"Tool to export Grafana dashboards keeping folder hierarchy and import on the other instance of Grafana","archived":false,"fork":false,"pushed_at":"2019-09-01T07:47:48.000Z","size":6,"stargazers_count":15,"open_issues_count":0,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-06T02:38:28.190Z","etag":null,"topics":["dashboards","export","grafana","import","migration"],"latest_commit_sha":null,"homepage":null,"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/molu8bits.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2019-04-18T19:36:18.000Z","updated_at":"2024-03-25T18:02:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"298cf2ac-a3d4-49f0-8a01-4d2f84f08bd1","html_url":"https://github.com/molu8bits/grafana-migration-tool","commit_stats":null,"previous_names":["molu8bits/grafana-migration-tool"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molu8bits%2Fgrafana-migration-tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molu8bits%2Fgrafana-migration-tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molu8bits%2Fgrafana-migration-tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molu8bits%2Fgrafana-migration-tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/molu8bits","download_url":"https://codeload.github.com/molu8bits/grafana-migration-tool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243933441,"owners_count":20370988,"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":["dashboards","export","grafana","import","migration"],"created_at":"2024-08-01T15:04:42.640Z","updated_at":"2025-03-16T21:18:08.885Z","avatar_url":"https://github.com/molu8bits.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Grafana Migration Tool\n\n\u003cb\u003eExport and Import dashboards in Grafana are extremaly easy.\u003c/b\u003e\n\n\u003cb\u003eUnless\u003c/b\u003e you have to import 200 dashboards to the new Grafana instance. \u003cb\u003eAnd\u003c/b\u003e the database must be switched from sqlite to MySQL. \u003cb\u003eAnd\u003c/b\u003e some datasources are different. \u003cb\u003eAnd\u003c/b\u003e source 200 dashboards are kept in ellegant directory structure which you want to migrate as well.\n\u003cb\u003eAnd\u003c/b\u003e at the end it turns out that the migration must be started from the beginning.\n\n\nTo solve such migration problem the below migrating script is created. It is designed for helping with migration of Grafana dashboards from one instance to another (e.g. switching from builtin SQLite to MySQL etc).\n\nPractically is possible to just migrate SQL scripts but it will not work for bigger instances, when the destination Grafana has already some dashboards or finally if datasources are defined differently.\nWith this script is possible also to easily migrate/import only one Grafana directory, so can be served as Grafana Dashboard backup tool.\n\n\n\n\u003cb\u003eWhat does the script do ?\u003c/b\u003e\n\nFor standard migration we can run it in 3 phases:\n1. Export dashboards keeping directory information.\n```sh\npython grafana-migration.py --export\n```\n\nIt saves Grafana folders definition into OUTPUT_DIRECTORY/grafana-folders.json and creates a local directory tree where it laters dumps each of the Dashboard into JSON file keeping name-convention we can see in Grafana UI.\n\n2. Import Grafana directory structure:\n```sh\npython grafana-migration.py --import_folders\n```\n\nIt searches for OUTPUT_DIRECTORY/grafana-folders.json and tries to import the file into destination Grafana. Only directory structure is created in this step.\n\n3. Import Grafana dashboards per subdirectory\n```sh\npython grafana-migration.py --import_dashboards_from K8S\npython grafana-migration.py --import_dashboards_from Cassandra\n```\n\nIt connects to remote Grafana to get uid numbers of previosly imported folders and after that reads every file inside folder OUTPUT_DIRECTORY/K8S/*json modifies the Id to match existing folder and then imports.\nThis must be repeated for each of the folders where we have exported dashboard json files.\n\n4. Delete folders hierarchy from Grafana\n```sh\npython grafana-migration.py --delete_folders\n```\nThis must be used carefully - as it removes any existing folder with its dashboards. Only dashboards from General folder would survive this operation.\nAnyway it helps cleanup during testing of this migration.\n\n\n# Preparation\nCreate API keys for the source and destination Grafana instances. Then inside of the script there are 5 VARIABLES which must be defined:\n\u003cp\u003eGF_URL_SRC - source Grafana url where we import dashboards from\u003c/p\u003e\n\u003cp\u003eGF_KEY_SRC - API Key for this source Grafana\u003c/p\u003e\n\u003cp\u003eGF_URL_DST - destination Grafana url where we import dashboards and folders into. Also delete operation uses only this endpoint.\u003c/p\u003e\n\u003cp\u003eGF_KEY_DST - API Key for this destination Grafana\u003c/p\u003e\n\n\u003cp\u003eIf deletion option is required then the last variable must be set: SURE_STRING\u003c/p\u003e\nSURE_STRING = 'Yes I want delete all the dashboards'\nOtherwise scripts do nothing.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmolu8bits%2Fgrafana-migration-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmolu8bits%2Fgrafana-migration-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmolu8bits%2Fgrafana-migration-tool/lists"}