---
title: "Manage resources with Grafana CLI | Grafana documentation"
description: "Learn more about the supported workflows and use cases for Grafana CLI"
---

# Manage resources with `grafanactl`

> Caution
> 
> `grafanactl` is being deprecated, and we’re bringing all our learning and experience into the new, improved CLI tool [`gcx`](/docs/grafana/latest/as-code/observability-as-code/grafana-cli/gcx/). The `grafanactl` repository in GitHub will be archived on June 1, 2026.
> 
> To migrate from `grafanactl` to `gcx`, search-and-replace `grafanactl` with `gcx`. For `grafanactl resources serve`, use `gcx dev serve` instead.

## Migrate resources between environments

Using the `config` and `resources` options, you can migrate Grafana resources from one environment to another, for example, from a development to production environment. The `config` option lets you define the configuration context. Using `resources` with `pull`, `push`, and `serve` lets you pull a defined resource from one instance, and push that resource to another instance. `Serve` allows you to preview changes locally before pushing.

Use these steps to migrate resources between environments:

> Note
> 
> Currently, the `serve` command only works with dashboards.

Use these steps to migrate resources between environments:

> Note
> 
> Resources are pulled and pushed from the `./resources` directory by default. This can be configured with the `-p, --path` flags to specify custom paths on disk.

1. Make changes to dashboards and other resources using the Grafana UI in your **development instance**.
2. Pull those resources from the development environment to your local machine:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl config use-context YOUR_CONTEXT
   grafanactl resources pull --path ./resources/ -o yaml
   ```
3. (Optional) Preview the resources locally before pushing:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl config use-context YOUR_CONTEXT
   grafanactl resources serve ./resources/
   ```
4. Switch to the **production instance** and push the resources:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl config use-context YOUR_CONTEXT
   grafanactl resources push -p ./resources/
   ```

## Back up Grafana resources

This workflow helps you back up all Grafana resources from one instance and later restore them. This is useful to replicate a configuration or perform disaster recovery.

1. Use `grafanactl` to pull all resources from your target environment:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl config use-context YOUR_CONTEXT
   grafanactl resources pull --path ./resources/ -o yaml
   ```
2. Save the exported resources to version control or cloud storage.

## Restore Grafana resources

1. (Optional) Preview the backup locally:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl config use-context YOUR_CONTEXT
   grafanactl resources serve ./resources/
   ```
2. To restore the resources later or restore them on another instance, push the saved resources:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl config use-context YOUR_CONTEXT
   grafanactl resources push -p ./resources/
   ```

## Manage dashboards as code

With this workflow, you can define and manage dashboards as code, saving them to a version control system like Git. This is useful for teams that want to maintain a history of changes, collaborate on dashboard design, and ensure consistency across environments.

1. Use a dashboard generation script (for example, with the [Foundation SDK](https://github.com/grafana/grafana-foundation-sdk)). You can find an example implementation in the Grafana as code [hands-on lab repository](https://github.com/grafana/dashboards-as-code-workshop/tree/main/part-one-golang-starter).
2. Serve and preview the output of the dashboard generator locally:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl config use-context YOUR_CONTEXT
   grafanactl resources serve --script 'go run scripts/generate-dashboard.go' --watch './scripts'
   ```
3. When the output looks correct, generate dashboard manifest files:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   go run scripts/generate-dashboard.go --generate-resource-manifests --output './resources'
   ```
4. Push the generated resources to your Grafana instance:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl config use-context YOUR_CONTEXT
   grafanactl resources push -p ./resources/
   ```

## Explore and modify resources from the terminal

This section describes how to use the Grafana CLI to interact with Grafana resources directly from your terminal. These commands allow you to browse, inspect, update, and delete resources without using the Grafana UI. This approach is useful for advanced users who want to manage resources more efficiently or integrate Grafana operations into automated workflows.

### Find and delete dashboards using invalid data sources

Use this workflow to identify dashboards that reference incorrect or outdated data sources, and remove them if necessary.

1. Set the context to the appropriate environment:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl config use-context YOUR_CONTEXT
   ```
2. Find dashboards using specific data sources:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl resources get dashboards -ojson | jq '.items | map({ uid: .metadata.name, datasources: .spec.panels | map(.datasource.uid)  })'
   [
      {
         "uid": "important-production-dashboard",
         "datasources": [
            "mimir-prod"
         ]
      },
      {
         "uid": "test-dashboard-from-dev",
         "datasources": [
            "mimir-prod",
            "mimir-dev"
         ]
      },
      {
         "uid": "test-dashboard-from-stg",
         "datasources": [
            "mimir-prod",
            "mimir-stg",
            "mimir-dev"
         ]
      }
   ]
   ```
   
   This command lists dashboard UIDs along with the data source UIDs used in their panels. You can then identify the dashboards that are using invalid or unexpected data sources.
3. Delete the identified dashboards directly:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl resources delete dashboards/test-dashboard-from-stg,test-dashboard-from-dev
   ✔ 2 resources deleted, 0 errors
   ```

### Find and deprecate dashboards using the old API version

Use this workflow to locate dashboards using a deprecated API version and mark them accordingly.

1. Set the context to the appropriate environment:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl config use-context YOUR_CONTEXT
   ```
2. List all available resources types and versions:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl resources list
   ```
   
   This command returns a list of resources, including their versions, types, and quantities:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   GROUP                               VERSION   KIND
   folder.grafana.app                  v1        folder
   dashboard.grafana.app               v1        dashboard
   dashboard.grafana.app               v1        librarypanel
   dashboard.grafana.app               v2        dashboard
   dashboard.grafana.app               v2        librarypanel
   playlist.grafana.app                v1        playlist
   ```
3. Find dashboards that are still using a deprecated API version:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl resources get dashboards.v1.dashboard.grafana.app
   ```
   
   This command returns a table displaying the resource type, resource name, and associated namespace:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   KIND         NAME                                   NAMESPACE
   dashboards   really-old-dashboard                   default
   ```
4. Edit each of these dashboards to add a `deprecated` tag:
   
   Bash ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```bash
   grafanactl resources edit dashboards.v1.dashboard.grafana.app/really-old-dashboard -p '{"spec":{"tags":["deprecated"]}}'
   ```

> Tip
> 
> You can get help by using the `grafanactl --help` command.
