Skip to content

Instantly share code, notes, and snippets.

@devcfgc
Created November 3, 2017 11:02
Show Gist options
  • Save devcfgc/c8e67af7f1c2389c230ac860da6a1a90 to your computer and use it in GitHub Desktop.
Save devcfgc/c8e67af7f1c2389c230ac860da6a1a90 to your computer and use it in GitHub Desktop.
backup grafana dashboard templates
#!/usr/bin/env bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
KEY=<api_token_key>
HOST="http://localhost:3000"
if [ ! -d $SCRIPT_DIR/dashboards ] ; then
mkdir -p $SCRIPT_DIR/dashboards
fi
for dash in $(curl -k -H "Authorization: Bearer $KEY" $HOST/api/search\?query\=\& |sed 's/{"id"/\\\n{"id"/g' |cut -d "," -f 3 | grep db |cut -d\" -f 4 |cut -d\/ -f2); do
curl -k -H "Authorization: Bearer $KEY" $HOST/api/dashboards/db/$dash | sed 's/"id":[0-9]\+,/"id":null,/' | sed 's/\(.*\)}/\1,"overwrite": true}/' > $SCRIPT_DIR/dashboards/$dash.json
done
@hbokh
Copy link

hbokh commented Aug 3, 2018

FYI I had to alter cut -d "," -f 3 and change the "3" into "4" to get the uri's to the db-files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment