|
| 1 | +# Grafana Dashboard Export Guide |
| 2 | + |
| 3 | +This guide provides step-by-step instructions to export dashboards from Grafana. You can export |
| 4 | +either a single dashboard directly through the Grafana interface or all dashboards within a |
| 5 | +specified folder using a custom script. |
| 6 | + |
| 7 | +## Exporting a Single Dashboard |
| 8 | + |
| 9 | +To export an individual dashboard directly through the Grafana interface, follow these steps: |
| 10 | + |
| 11 | +1. Open the dashboard you wish to export. |
| 12 | +2. Click the Share button (usually located at the top right). |
| 13 | +3. In the Share panel, navigate to the Export tab. |
| 14 | +4. Select Save to file. This will download a JSON file of the dashboard's configuration to your |
| 15 | + computer. |
| 16 | + |
| 17 | +## Exporting All Dashboards in a Folder |
| 18 | + |
| 19 | +The following steps outline a method to export all dashboards within a specified folder in Grafana |
| 20 | +as a single zip file containing individual JSON files for each dashboard. |
| 21 | + |
| 22 | +### 1. Open the Browser Console |
| 23 | + |
| 24 | +- Open your Grafana instance and log in if prompted by SSO. |
| 25 | +- Press <kbd>F12</kbd> (or right-click and select **Inspect**) to open Developer Tools. |
| 26 | +- Navigate to the **Console** tab. |
| 27 | + |
| 28 | +### 2. Load JSZip Library |
| 29 | + |
| 30 | +- To manage multiple files in a zip, we’ll use the [JSZip library](https://stuk.github.io/jszip/). |
| 31 | + Copy and paste the following code into the console and press <kbd>Enter</kbd>: |
| 32 | + |
| 33 | + ```javascript |
| 34 | + var script = document.createElement('script'); |
| 35 | + script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js'; |
| 36 | + document.head.appendChild(script); |
| 37 | + ``` |
| 38 | + |
| 39 | +- Verify that JSZip is loaded by typing `JSZip` into the console and pressing <kbd>Enter</kbd>. You |
| 40 | + should |
| 41 | + see an object or function returned. |
| 42 | + |
| 43 | +### 3. Run the Export Script |
| 44 | + |
| 45 | +- Copy and paste the following code into the console and press <kbd>Enter</kbd>: |
| 46 | + |
| 47 | + ```javascript |
| 48 | + async function exportAllDashboardsWithFolders() { |
| 49 | + const zip = new JSZip(); |
| 50 | + |
| 51 | + // Step 1: Get all folders |
| 52 | + const folderResponse = await fetch(`/api/folders`); |
| 53 | + const folders = await folderResponse.json(); |
| 54 | + const folderMap = {}; |
| 55 | + folders.forEach(folder => { |
| 56 | + folderMap[folder.uid] = folder.title.replace(/[/\\?%*:|"<>]/g, ''); // Clean up folder names |
| 57 | + }); |
| 58 | + |
| 59 | + // Step 2: Fetch all dashboards across folders |
| 60 | + const response = await fetch(`/api/search?type=dash-db`); |
| 61 | + const dashboards = await response.json(); |
| 62 | + |
| 63 | + for (const dashboard of dashboards) { |
| 64 | + const uid = dashboard.uid; |
| 65 | + const title = dashboard.title.replace(/[/\\?%*:|"<>]/g, ''); // Clean up filename |
| 66 | + const folderName = folderMap[dashboard.folderUid] || 'General'; |
| 67 | + |
| 68 | + // Fetch each dashboard's JSON |
| 69 | + const dashboardResponse = await fetch(`/api/dashboards/uid/${uid}`); |
| 70 | + const dashboardData = await dashboardResponse.json(); |
| 71 | + |
| 72 | + // Add each dashboard JSON to the zip, organized by folder |
| 73 | + zip.file(`${folderName}/${title}.json`, JSON.stringify(dashboardData.dashboard, null, 2)); |
| 74 | + console.log(`Added to zip: ${folderName}/${title}`); |
| 75 | + } |
| 76 | + |
| 77 | + // Step 3: Generate the zip and trigger download |
| 78 | + zip.generateAsync({ type: 'blob' }).then(function (content) { |
| 79 | + const link = document.createElement('a'); |
| 80 | + link.href = URL.createObjectURL(content); |
| 81 | + link.download = 'grafana_dashboards.zip'; |
| 82 | + document.body.appendChild(link); |
| 83 | + link.click(); |
| 84 | + document.body.removeChild(link); |
| 85 | + console.log("Downloaded all dashboards as zip with folder structure."); |
| 86 | + }); |
| 87 | + } |
| 88 | + |
| 89 | + exportAllDashboardsWithFolders(); |
| 90 | + ``` |
| 91 | +- The script will create a zip containing individual JSON files for each dashboard and will follow |
| 92 | + Grafana folder structure. |
| 93 | +- Each JSON file is named after the dashboard title and represents a backup of the dashboard’s |
| 94 | + configuration. |
0 commit comments