It's possible to do search-and-replace on Grafana dashboard definitions by directly manipulating the SQLite database. The key steps after logging into the server are as follows:
cd /var/lib/grafana
# Make backup copy; preserve old backup copies
sudo cp --backup=numbered grafana.db grafana.db.bak
# Stop Grafana
sudo systemctl stop grafana-server
# Open database
sudo sqlite3 grafana.db
# Check how many definitions contain the string to be replaced.
# Note that using isntr() is superior to LIKE, since it's case sensitive and
# deals with multi-line strings correctly
SELECT COUNT(*) FROM dashboard WHERE instr(data, 'replaceme') > 0;
# Do search and replace on dashboard definition
UPDATE dashboard SET data = replace( data, 'replaceme', 'replaced' ) WHERE instr(data, 'replaceme') > 0;
# Can do count check again to ensure replacement has been successful
SELECT COUNT(*) FROM dashboard WHERE data LIKE '%replaceme%';
# Quit SQLite
.quit
# Start Grafana again
sudo systemctl start grafana-server
Some useful SQLite commands:
.tables
shows all tables.schema tablename
shows schema of specific table.headers ON
turns on table headers for output ofSELECT
statements