-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafana-backup.sh
executable file
·35 lines (28 loc) · 1.35 KB
/
grafana-backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/bash
set -o errexit
set -o pipefail
set -o nounset
BACKUP_DIR="./grafana.backup"
HOST="$IOT_HOST:3000"
PWD=$GRAFANA_PASSWORD
USR=$GRAFANA_USER
# -------------------------------------------------------------------------------------------------------
# --- Data Sources
# -------------------------------------------------------------------------------------------------------
echo "Exporting Grafana datasources from $HOST"
if [ ! -d $BACKUP_DIR/datasources ] ; then
mkdir -p $BACKUP_DIR/datasources
fi
curl -s "http://$HOST/api/datasources" -u $USR:$PWD | jq -c -M '.[]'|split -l 1 - $BACKUP_DIR/datasources/
# -------------------------------------------------------------------------------------------------------
# --- Dashboard
# -------------------------------------------------------------------------------------------------------
echo "Exporting Grafana dashboards from $HOST"
if [ ! -d $BACKUP_DIR/dashboards ] ; then
mkdir -p $BACKUP_DIR/dashboards
fi
for dash in $(curl -s "http://$HOST/api/search" -u $USR:$PWD | jq -r '.[] | select(.type == "dash-db") | .uid'); do
curl -s "http://$HOST/api/dashboards/uid/$dash" -u $USR:$PWD > $BACKUP_DIR/dashboards/${dash}.json
slug=$(cat $BACKUP_DIR/dashboards/${dash}.json | jq -r '.meta.slug')
mv $BACKUP_DIR/dashboards/${dash}.json $BACKUP_DIR/dashboards/${dash}-${slug}.json
done