Created
December 3, 2019 14:55
-
-
Save AstraSerg/8d567b2d6cdb1fe7dc88f4c3b91378a4 to your computer and use it in GitHub Desktop.
Convert grafana SQLite DB to postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cat command | |
load database | |
from '/var/spool/grafana_data/grafana.db' | |
into postgresql://grafana:password@localhost/grafana | |
with include drop, create tables, create indexes, reset sequences | |
set work_mem to '16MB', maintenance_work_mem to '512 MB'; | |
============== | |
# cat convert.sh | |
#!/bin/bash | |
# https://stackoverflow.com/a/30544492/2733113 | |
pgloader -v command | |
# pgloader ./grafana.db postgresql://grafana:230j9dm2q9c@localhost/grafana | |
============== | |
./convert.sh | |
============== | |
# cat fix_int_boolean.sh | |
#!/bin/bash | |
params='alert silenced | |
alert_notification is_default false | |
alert_notification send_reminder false | |
alert_notification disable_resolve_message false | |
dashboard is_folder false | |
dashboard has_acl false | |
dashboard_snapshot external | |
data_source basic_auth | |
data_source is_default | |
data_source read_only | |
data_source with_credentials false | |
migration_log success | |
plugin_setting enabled | |
plugin_setting pinned | |
team_member external | |
temp_user email_sent | |
user is_admin | |
user email_verified | |
user is_disabled false | |
user_auth_token auth_token_seen' | |
function create_req { | |
table=$1 | |
col=$2 | |
default=$3 | |
echo "ALTER TABLE $table ALTER COLUMN $col DROP DEFAULT;" | |
echo "ALTER TABLE $table ALTER COLUMN $col TYPE bool USING CASE WHEN $col=0 THEN FALSE ELSE TRUE END;" | |
[ -n "$default" ] && \ | |
echo "ALTER TABLE $table ALTER COLUMN $col SET DEFAULT $default;" | |
echo | |
} | |
echo "$params" | while read l; do | |
create_req $l | |
done | |
============== | |
./fix_int_boolean.sh | |
============== | |
execute in postgres |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment