CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-grafana-backup

A Python-based application to backup Grafana settings using the Grafana API

Pending
Overview
Eval results
Files

backup-operations.mddocs/

Backup Operations

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.

Capabilities

Main Backup Function

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
    """

Supported Components

All backup operations support the following Grafana component types:

Dashboard Backup

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
    """

Datasource Backup

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
    """

Folder Backup

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
    """

Alert Channel Backup

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
    """

Alert Rules Backup

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
    """

Organization Backup

def main(args, settings):
    """
    Backup organization configurations
    
    Module: grafana_backup.save_orgs
    Output: JSON files in organizations/{timestamp}/ directory
    Requires: Basic authentication (admin credentials)
    """

User Backup

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
    """

Team Backup

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
    """

Team Member Backup

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
    """

Snapshot Backup

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
    """

Dashboard Version Backup

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
    """

Annotation Backup

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
    """

Library Element Backup

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
    """

Contact Point Backup

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
    """

Notification Policy Backup

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
    """

Usage Examples

Complete System Backup

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)

Selective Component Backup

# Backup only dashboards and datasources
args = {
    'save': True, 
    '--components': 'dashboards,datasources',
    '--no-archive': False,
    '--config': None
}

save_backup(args, settings)

Backup Without Archiving

# Backup but skip archive creation (for troubleshooting)
args = {
    'save': True,
    '--components': None,
    '--no-archive': True,
    '--config': None
}

save_backup(args, settings)

Component Dependencies

The backup system includes API feature detection to ensure compatibility:

  • UID Support: Automatically detected for dashboards and datasources
  • Paging Support: Used for large datasets in Grafana 6.2+
  • Contact Point Support: Checked for unified alerting features
  • Basic Auth: Required for user, organization, and team operations

Output Structure

Backups are organized in timestamped directories:

_OUTPUT_/
├── {timestamp}/
│   ├── dashboards/{timestamp}/
│   ├── datasources/{timestamp}/
│   ├── folders/{timestamp}/
│   ├── alert_channels/{timestamp}/
│   ├── organizations/{timestamp}/
│   ├── users/{timestamp}/
│   └── ...
└── backup_{timestamp}.tar.gz

Cloud Storage Integration

After local backup completion, files are automatically uploaded to configured cloud storage:

  • AWS S3: Uploads to specified S3 bucket and key prefix
  • Azure Storage: Uploads to Azure Storage container
  • Google Cloud Storage: Uploads to GCS bucket using service account

Error Handling

The backup system includes comprehensive error handling:

  • API connectivity validation before backup starts
  • Authentication verification for all operations
  • Graceful handling of missing components
  • Detailed logging for troubleshooting
  • Automatic cleanup on critical failures

Install with Tessl CLI

npx tessl i tessl/pypi-grafana-backup

docs

admin-tools.md

api-health.md

archive-management.md

backup-operations.md

cloud-storage.md

configuration.md

delete-operations.md

index.md

monitoring.md

restore-operations.md

tile.json