or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

admin-tools.mdapi-health.mdarchive-management.mdbackup-operations.mdcloud-storage.mdconfiguration.mddelete-operations.mdindex.mdmonitoring.mdrestore-operations.md

delete-operations.mddocs/

0

# Delete Operations

1

2

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.

3

4

## Capabilities

5

6

### Main Delete Function

7

8

The primary delete entry point that orchestrates component deletion with API validation and selective component processing.

9

10

```python { .api }

11

def main(args, settings):

12

"""

13

Main delete function that handles selective component deletion

14

15

Args:

16

args (dict): Command line arguments including:

17

- '--components': Comma-separated list of components to delete

18

settings (dict): Configuration settings loaded from grafanaSettings

19

"""

20

```

21

22

## Supported Delete Components

23

24

The delete system supports a subset of components with safety considerations:

25

26

### Dashboard Deletion

27

```python { .api }

28

def main(args, settings):

29

"""

30

Delete all dashboards from Grafana instance

31

32

Module: grafana_backup.delete_dashboards

33

Features: UID-based deletion, folder handling, bulk operations

34

Safety: Confirmation prompts, selective deletion by folder

35

"""

36

```

37

38

### Datasource Deletion

39

```python { .api }

40

def main(args, settings):

41

"""

42

Delete all datasources from Grafana instance

43

44

Module: grafana_backup.delete_datasources

45

Features: UID-based deletion, dependency checking

46

Safety: Validates no dashboards are using datasources before deletion

47

"""

48

```

49

50

### Folder Deletion

51

```python { .api }

52

def main(args, settings):

53

"""

54

Delete all folders from Grafana instance

55

56

Module: grafana_backup.delete_folders

57

Features: Recursive deletion, dashboard handling

58

Safety: Moves dashboards to General folder before folder deletion

59

"""

60

```

61

62

### Alert Channel Deletion

63

```python { .api }

64

def main(args, settings):

65

"""

66

Delete all alert notification channels

67

68

Module: grafana_backup.delete_alert_channels

69

Features: Channel type handling, bulk deletion

70

Safety: Validates no active alerts are using channels

71

"""

72

```

73

74

### Snapshot Deletion

75

```python { .api }

76

def main(args, settings):

77

"""

78

Delete all dashboard snapshots

79

80

Module: grafana_backup.delete_snapshots

81

Features: Bulk snapshot removal, key-based deletion

82

Safety: Snapshot deletion is generally safe as they're copies

83

"""

84

```

85

86

### Annotation Deletion

87

```python { .api }

88

def main(args, settings):

89

"""

90

Delete all annotations from dashboards and global scope

91

92

Module: grafana_backup.delete_annotations

93

Features: Time-range deletion, tag-based filtering

94

Safety: Preserves system annotations, focuses on user annotations

95

"""

96

```

97

98

### Library Element Deletion

99

```python { .api }

100

def main(args, settings):

101

"""

102

Delete all library elements (reusable panels and variables)

103

104

Module: grafana_backup.delete_library_elements

105

Features: Element type handling, dependency checking

106

Safety: Validates no dashboards are using elements before deletion

107

"""

108

```

109

110

### Team Member Deletion

111

```python { .api }

112

def main(args, settings):

113

"""

114

Remove all team members from all teams

115

116

Module: grafana_backup.delete_team_members

117

Features: Preserves team structure, removes only memberships

118

Safety: Teams themselves are preserved to maintain references

119

"""

120

```

121

122

## Excluded Components

123

124

Several component types are intentionally excluded from deletion operations for safety:

125

126

### Teams Not Deleted

127

Teams themselves are not deleted because they don't have consistent unique identifiers across Grafana instances. Deleting and recreating teams would break:

128

- Folder permission references

129

- Team member associations

130

- Historical audit trails

131

132

### Organizations Not Deleted

133

Organization deletion is not supported to prevent:

134

- Complete data loss scenarios

135

- Multi-tenant configuration destruction

136

- License and user limit complications

137

138

### Users Not Deleted

139

User deletion is not supported to preserve:

140

- Historical audit trails

141

- Dashboard ownership references

142

- Permission and role assignments

143

144

## Usage Examples

145

146

### Delete All Dashboards

147

```python

148

from grafana_backup.delete import main as delete_components

149

from grafana_backup.grafanaSettings import main as load_config

150

151

# Load configuration

152

settings = load_config('/path/to/grafanaSettings.json')

153

154

# Delete all dashboards

155

args = {

156

'delete': True,

157

'--components': 'dashboards',

158

'--config': None

159

}

160

161

delete_components(args, settings)

162

```

163

164

### Delete Multiple Component Types

165

```python

166

# Delete dashboards, datasources, and folders

167

args = {

168

'delete': True,

169

'--components': 'dashboards,datasources,folders',

170

'--config': None

171

}

172

173

delete_components(args, settings)

174

```

175

176

### Delete All Supported Components

177

```python

178

# Delete all components that support deletion

179

args = {

180

'delete': True,

181

'--components': None, # None means all supported components

182

'--config': None

183

}

184

185

delete_components(args, settings)

186

```

187

188

## Component-Specific Deletion Details

189

190

### Dashboard Deletion Strategy

191

The dashboard deletion process:

192

1. Retrieves all dashboards using search API

193

2. Handles both ID-based and UID-based deletion depending on Grafana version

194

3. Processes dashboards in batches for performance

195

4. Preserves folder structure during deletion

196

197

### Datasource Deletion Strategy

198

The datasource deletion process:

199

1. Lists all datasources in the organization

200

2. Checks for dashboard dependencies (optional safety check)

201

3. Uses UID-based deletion when supported

202

4. Handles built-in datasources appropriately

203

204

### Folder Deletion Strategy

205

The folder deletion process:

206

1. Moves all dashboards from folders to General folder

207

2. Updates folder permissions and references

208

3. Deletes folders in reverse hierarchy order

209

4. Preserves General folder (cannot be deleted)

210

211

### Library Element Deletion Strategy

212

The library element deletion process:

213

1. Retrieves all library elements by type

214

2. Checks for dashboard usage dependencies

215

3. Deletes elements that are not in use

216

4. Provides warnings for elements still in use

217

218

## Safety Features

219

220

### API Validation

221

All delete operations include comprehensive API validation:

222

- Grafana connectivity and authentication verification

223

- Feature support detection (UID, paging, etc.)

224

- Permission validation for delete operations

225

226

### Dependency Checking

227

Where applicable, the system checks for dependencies:

228

- Dashboards using datasources before datasource deletion

229

- Dashboards using library elements before element deletion

230

- Team references before team member removal

231

232

### Confirmation and Logging

233

Delete operations include extensive logging:

234

- Pre-deletion validation results

235

- Individual item deletion status

236

- Error handling and recovery information

237

- Summary of deletion operations

238

239

### Graceful Error Handling

240

The delete system handles errors gracefully:

241

- Continues with remaining items if individual deletions fail

242

- Provides detailed error messages for troubleshooting

243

- Preserves system stability during bulk operations

244

- Exits cleanly on API connectivity issues

245

246

## Best Practices

247

248

### Backup Before Deletion

249

Always create a backup before performing delete operations:

250

```bash

251

# Create backup first

252

grafana-backup save

253

254

# Then perform deletion

255

grafana-backup delete --components=dashboards

256

```

257

258

### Selective Deletion

259

Use selective deletion rather than bulk deletion when possible:

260

```bash

261

# Delete specific components only

262

grafana-backup delete --components=snapshots,annotations

263

```

264

265

### Test with Non-Production

266

Test deletion operations in development environments before production use:

267

- Verify component selection works as expected

268

- Validate safety checks are appropriate

269

- Confirm restoration process if needed

270

271

### Monitor Dependencies

272

Be aware of component dependencies:

273

- Dashboards depend on datasources and library elements

274

- Folders contain dashboards and have permissions

275

- Teams have members and folder permissions

276

- Alert channels may be used by dashboard alerts

277

278

The delete system is designed to be safe but irreversible, so careful planning and testing are essential.