Python script to migrate dashboards and folder structure from one Grafana instance to another.
- Migrates complete folder structure
- Preserves dashboard folder organization
- Maintains dashboard configurations
- Shows detailed migration progress
- Handles errors gracefully
- Python 3.6+
requests
library- API access tokens for both Grafana instances
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
Set the following environment variables:
export SOURCE_TOKEN="your-source-grafana-token"
export TARGET_TOKEN="your-target-grafana-token"
Update the URLs in the script:
SOURCE_URL = "http://old-grafana:3000"
TARGET_URL = "http://new-grafana:3000"
Run the script:
python grafana_migrator.py
The script will:
- Create the folder structure from source Grafana
- Migrate dashboards to their respective folders
- Show progress and any errors during migration
pip install pytest
pytest test_grafana_migrator.py -v
Project uses flake8 with custom configuration:
# .flake8
[flake8]
extend-ignore = C901
To check code style:
flake8 .
Required permissions for both source and target tokens:
- Folders: Read/Write
- Dashboards: Read/Write
The script handles common errors:
- Network connectivity issues
- API authentication errors
- Missing folders
- Dashboard import failures
Each error is logged with the specific dashboard or folder affected.
Feel free to submit issues and enhancement requests.