-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup_grafana.sh
executable file
·38 lines (28 loc) · 1.01 KB
/
backup_grafana.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
36
37
38
#!/bin/bash
set -e
export GRAFANA_TOKEN=''
export GRAFANA_URL='http://localhost:3000'
script_path=$(dirname ${BASH_SOURCE[0]})
current_path=$(realpath $script_path)
current_time=`date +"%Y-%m-%d-%H%M%S"`
backup_dir=/tmp/grafana_backup_$current_time
backup_dir_compressed=$backup_dir.tar.gz
echo $current_time
dashboard_backup_path="$backup_dir/dashboards"
datasource_backup_path="$backup_dir/datasources"
folders_backup_path="$backup_dir/folders"
if [ ! -d "$dashboard_backup_path" ]; then
mkdir -p "$dashboard_backup_path"
fi
if [ ! -d "$datasource_backup_path" ]; then
mkdir -p "$datasource_backup_path"
fi
if [ ! -d "$folders_backup_path" ]; then
mkdir -p "$folders_backup_path"
fi
python "${current_path}/saveDashboards.py" $dashboard_backup_path || exit 0
python "${current_path}/saveDatasources.py" $datasource_backup_path || exit 0
python "${current_path}/saveFolders.py" $folders_backup_path || exit 0
tar -zcvf $backup_dir_compressed -C $backup_dir .
rm -rf $backup_dir
echo "create backup $backup_dir_compressed"