Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############################################################ IDENT(1)
- #
- # $Title: Script to make backup of Grafana dashboards $
- # $Copyright: 2019 Devin Teske. All rights reserved. $
- # $FrauBSD$
- #
- ############################################################ CONFIGURATION
- GRAFANA_DB= /var/lib/grafana/grafana.db
- TABLE= dashboard
- KEYS= slug, data
- ############################################################ TARGETS
- all:
- @sqlite3 $(GRAFANA_DB) 'select $(KEYS) from $(TABLE)' | awk ' \
- function have(name) \
- { \
- return system(sprintf("type %s > %s 2>&1", \
- name, "/dev/null")) == 0; \
- } \
- function exists(path) \
- { \
- return system("[ -e " path " ]") == 0; \
- } \
- function cat(file, line, buf) \
- { \
- if (!exists(file)) return ""; \
- while ((getline line < file) != 0) \
- buf = buf "\n" line; \
- close(file); \
- return substr(buf, 2); \
- } \
- BEGIN { \
- jq = have("jq") ? "jq ." : "cat"; \
- } \
- match($$0, /\|/) { \
- slug = substr($$0, 1, RSTART - 1); \
- data = substr($$0, RSTART + 1); \
- prev = cat(file = slug ".json"); \
- jcmd = sprintf("%s > %s", jq, file); \
- print data | jcmd; \
- close(jcmd); \
- data = cat(file); \
- if (data != prev) printf "U %s\n", file; \
- } \
- ' # END-QUOTE
- ################################################################################
- # END
- ################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement