A Python-based application to backup Grafana settings using the Grafana API
—
Complete backup functionality for all supported Grafana components. The backup system captures configuration data for dashboards, datasources, folders, users, teams, and other Grafana objects, storing them as JSON files with automatic archiving and cloud storage integration.
The primary backup entry point that orchestrates the entire backup process, including component selection, API validation, and post-backup archiving.
def main(args, settings):
"""
Main backup function that handles the complete backup workflow
Args:
args (dict): Command line arguments including:
- '--components': Comma-separated list of components to backup
- '--no-archive': Skip archive creation if True
settings (dict): Configuration settings loaded from grafanaSettings
"""All backup operations support the following Grafana component types:
def main(args, settings):
"""
Backup all dashboards with their complete configuration
Module: grafana_backup.save_dashboards
Output: JSON files in dashboards/{timestamp}/ directory
Features: UID support, paging for large datasets, version preservation
"""def main(args, settings):
"""
Backup all datasource configurations
Module: grafana_backup.save_datasources
Output: JSON files in datasources/{timestamp}/ directory
Features: UID support, credential handling, connection validation
"""def main(args, settings):
"""
Backup folder structure, hierarchy, and permissions
Module: grafana_backup.save_folders
Output: JSON files in folders/{timestamp}/ and folder_permissions/{timestamp}/ directories
Features: Permission preservation, nested folder support, UID-based folders
Note: Folder permissions are automatically backed up with folders and saved
as separate folder_permission files for restoration dependency management
"""def main(args, settings):
"""
Backup alert notification channels
Module: grafana_backup.save_alert_channels
Output: JSON files in alert_channels/{timestamp}/ directory
Features: Channel type preservation, credential handling
"""def main(args, settings):
"""
Backup unified alerting rules (Grafana 9.4.0+)
Module: grafana_backup.save_alert_rules
Output: JSON files in alert_rules/{timestamp}/ directory
Features: Rule group preservation, expression handling
"""def main(args, settings):
"""
Backup organization configurations
Module: grafana_backup.save_orgs
Output: JSON files in organizations/{timestamp}/ directory
Requires: Basic authentication (admin credentials)
"""def main(args, settings):
"""
Backup user accounts and roles
Module: grafana_backup.save_users
Output: JSON files in users/{timestamp}/ directory
Requires: Basic authentication (admin credentials)
Note: Passwords are not backed up; default password is used during restore
"""def main(args, settings):
"""
Backup team configurations
Module: grafana_backup.save_teams
Output: JSON files in teams/{timestamp}/ directory
Features: Team metadata and settings preservation
"""def main(args, settings):
"""
Backup team membership and role assignments
Module: grafana_backup.save_team_members
Output: JSON files in team_members/{timestamp}/ directory
Requires: Basic authentication for complete team access
"""def main(args, settings):
"""
Backup dashboard snapshots
Module: grafana_backup.save_snapshots
Output: JSON files in snapshots/{timestamp}/ directory
Features: Complete snapshot data including metadata
"""def main(args, settings):
"""
Backup dashboard version history (backup only, no restore)
Module: grafana_backup.save_dashboard_versions
Output: JSON files in dashboard_versions/{timestamp}/ directory
Note: Version history is preserved but cannot be restored
"""def main(args, settings):
"""
Backup dashboard and global annotations
Module: grafana_backup.save_annotations
Output: JSON files in annotations/{timestamp}/ directory
Features: Time range and tag preservation
"""def main(args, settings):
"""
Backup reusable library elements (panels, variables)
Module: grafana_backup.save_library_elements
Output: JSON files in library_elements/{timestamp}/ directory
Features: Element type and model preservation
"""def main(args, settings):
"""
Backup alerting contact points (unified alerting)
Module: grafana_backup.save_contact_points
Output: JSON files in contact_points/{timestamp}/ directory
Requires: Contact point support in Grafana version
"""def main(args, settings):
"""
Backup notification policies for unified alerting
Module: grafana_backup.save_notification_policies
Output: JSON files in notification_policies/{timestamp}/ directory
Features: Policy tree structure preservation
"""from grafana_backup.save import main as save_backup
from grafana_backup.grafanaSettings import main as load_config
# Load configuration
settings = load_config('/path/to/grafanaSettings.json')
# Backup all components
args = {
'save': True,
'--components': None, # None means all components
'--no-archive': False,
'--config': None
}
save_backup(args, settings)# Backup only dashboards and datasources
args = {
'save': True,
'--components': 'dashboards,datasources',
'--no-archive': False,
'--config': None
}
save_backup(args, settings)# Backup but skip archive creation (for troubleshooting)
args = {
'save': True,
'--components': None,
'--no-archive': True,
'--config': None
}
save_backup(args, settings)The backup system includes API feature detection to ensure compatibility:
Backups are organized in timestamped directories:
_OUTPUT_/
├── {timestamp}/
│ ├── dashboards/{timestamp}/
│ ├── datasources/{timestamp}/
│ ├── folders/{timestamp}/
│ ├── alert_channels/{timestamp}/
│ ├── organizations/{timestamp}/
│ ├── users/{timestamp}/
│ └── ...
└── backup_{timestamp}.tar.gzAfter local backup completion, files are automatically uploaded to configured cloud storage:
The backup system includes comprehensive error handling:
Install with Tessl CLI
npx tessl i tessl/pypi-grafana-backup