A Python-based application to backup Grafana settings using the Grafana API
—
Selective deletion functionality for Grafana components. The delete system provides safe removal of Grafana objects with component-specific deletion strategies and safety measures to prevent accidental data loss.
The primary delete entry point that orchestrates component deletion with API validation and selective component processing.
def main(args, settings):
"""
Main delete function that handles selective component deletion
Args:
args (dict): Command line arguments including:
- '--components': Comma-separated list of components to delete
settings (dict): Configuration settings loaded from grafanaSettings
"""The delete system supports a subset of components with safety considerations:
def main(args, settings):
"""
Delete all dashboards from Grafana instance
Module: grafana_backup.delete_dashboards
Features: UID-based deletion, folder handling, bulk operations
Safety: Confirmation prompts, selective deletion by folder
"""def main(args, settings):
"""
Delete all datasources from Grafana instance
Module: grafana_backup.delete_datasources
Features: UID-based deletion, dependency checking
Safety: Validates no dashboards are using datasources before deletion
"""def main(args, settings):
"""
Delete all folders from Grafana instance
Module: grafana_backup.delete_folders
Features: Recursive deletion, dashboard handling
Safety: Moves dashboards to General folder before folder deletion
"""def main(args, settings):
"""
Delete all alert notification channels
Module: grafana_backup.delete_alert_channels
Features: Channel type handling, bulk deletion
Safety: Validates no active alerts are using channels
"""def main(args, settings):
"""
Delete all dashboard snapshots
Module: grafana_backup.delete_snapshots
Features: Bulk snapshot removal, key-based deletion
Safety: Snapshot deletion is generally safe as they're copies
"""def main(args, settings):
"""
Delete all annotations from dashboards and global scope
Module: grafana_backup.delete_annotations
Features: Time-range deletion, tag-based filtering
Safety: Preserves system annotations, focuses on user annotations
"""def main(args, settings):
"""
Delete all library elements (reusable panels and variables)
Module: grafana_backup.delete_library_elements
Features: Element type handling, dependency checking
Safety: Validates no dashboards are using elements before deletion
"""def main(args, settings):
"""
Remove all team members from all teams
Module: grafana_backup.delete_team_members
Features: Preserves team structure, removes only memberships
Safety: Teams themselves are preserved to maintain references
"""Several component types are intentionally excluded from deletion operations for safety:
Teams themselves are not deleted because they don't have consistent unique identifiers across Grafana instances. Deleting and recreating teams would break:
Organization deletion is not supported to prevent:
User deletion is not supported to preserve:
from grafana_backup.delete import main as delete_components
from grafana_backup.grafanaSettings import main as load_config
# Load configuration
settings = load_config('/path/to/grafanaSettings.json')
# Delete all dashboards
args = {
'delete': True,
'--components': 'dashboards',
'--config': None
}
delete_components(args, settings)# Delete dashboards, datasources, and folders
args = {
'delete': True,
'--components': 'dashboards,datasources,folders',
'--config': None
}
delete_components(args, settings)# Delete all components that support deletion
args = {
'delete': True,
'--components': None, # None means all supported components
'--config': None
}
delete_components(args, settings)The dashboard deletion process:
The datasource deletion process:
The folder deletion process:
The library element deletion process:
All delete operations include comprehensive API validation:
Where applicable, the system checks for dependencies:
Delete operations include extensive logging:
The delete system handles errors gracefully:
Always create a backup before performing delete operations:
# Create backup first
grafana-backup save
# Then perform deletion
grafana-backup delete --components=dashboardsUse selective deletion rather than bulk deletion when possible:
# Delete specific components only
grafana-backup delete --components=snapshots,annotationsTest deletion operations in development environments before production use:
Be aware of component dependencies:
The delete system is designed to be safe but irreversible, so careful planning and testing are essential.
Install with Tessl CLI
npx tessl i tessl/pypi-grafana-backup