-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
250 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,5 +46,4 @@ install -m 755 dist/grafana-db-migrator %{buildroot}%{_sbindir}/ | |
- Add fixes for CHAR fields | ||
|
||
* Tue Nov 02 2021 Nikita Beletskii <[email protected]> - 1.0.1-1 | ||
- Creating package for grafana-db-migrator | ||
|
||
- Creating package for grafana-db-migrator |
This file contains 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
12 changes: 12 additions & 0 deletions
12
update/ansible/playbook/tasks/roles/grafana/files/grafana.ini
This file contains 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
This file contains 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
This file contains 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
122 changes: 122 additions & 0 deletions
122
update/ansible/playbook/tasks/roles/sqlite-to-postgres/tasks/main.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
--- | ||
- name: Create Grafana backup dir | ||
file: | ||
path: "/srv/backup/grafana" | ||
state: directory | ||
owner: grafana | ||
group: grafana | ||
mode: '0700' | ||
|
||
- name: Stop grafana before upgrade | ||
supervisorctl: | ||
name: 'grafana' | ||
state: stopped | ||
|
||
- name: Create backup for SQLite Grafana database | ||
copy: | ||
src: /srv/grafana/grafana.db | ||
dest: "/srv/backup/grafana/grafana.db" | ||
owner: grafana | ||
group: grafana | ||
mode: '0700' | ||
|
||
- name: Remove all ` symbols in grafana dashboard description | ||
command: sqlite3 /srv/grafana/grafana.db -cmd ".timeout 60000" "UPDATE dashboard SET data = REPLACE(data, '`', '');" | ||
changed_when: True | ||
|
||
- name: Disable provisioning before change database | ||
ini_file: | ||
dest: /etc/grafana/grafana.ini | ||
section: paths | ||
option: provisioning | ||
value: conf/provisioning_disable | ||
|
||
- name: Switch to postgres | ||
ini_file: | ||
dest: /etc/grafana/grafana.ini | ||
section: database | ||
option: type | ||
value: postgres | ||
|
||
- name: Set database host | ||
ini_file: | ||
dest: /etc/grafana/grafana.ini | ||
section: database | ||
option: host | ||
value: localhost | ||
|
||
- name: Set database user | ||
ini_file: | ||
dest: /etc/grafana/grafana.ini | ||
section: database | ||
option: user | ||
value: grafana | ||
|
||
- name: Set database password | ||
ini_file: | ||
dest: /etc/grafana/grafana.ini | ||
section: database | ||
option: password | ||
value: grafana | ||
|
||
- name: Start grafana again | ||
supervisorctl: | ||
name: grafana | ||
state: restarted | ||
ignore_errors: yes | ||
|
||
- name: Check if initial data were created | ||
postgresql_query: | ||
db: grafana | ||
query: SELECT 1 FROM org WHERE id=1 | ||
retries: 3 | ||
delay: 3 | ||
register: psql_result | ||
until: psql_result.rowcount == 1 | ||
when: not ansible_check_mode | ||
|
||
- name: Wait for grafana database initialization | ||
pause: | ||
seconds: 10 | ||
|
||
- name: Stop grafana before upgrade | ||
supervisorctl: | ||
name: grafana | ||
state: stopped | ||
|
||
- name: Remove default admin user | ||
postgresql_query: | ||
db: grafana | ||
query: DELETE FROM public.user WHERE login='admin' | ||
when: not ansible_check_mode | ||
|
||
- name: Run grafana migrator | ||
command: grafana-db-migrator --change-char-to-text /srv/grafana/grafana.db "postgres://grafana:grafana@localhost:5432/grafana?sslmode=disable" | ||
register: migrator_output | ||
changed_when: "'All done' in migrator_output.stdout" | ||
|
||
- name: Enable provisioning after change database | ||
ini_file: | ||
dest: /etc/grafana/grafana.ini | ||
section: paths | ||
option: provisioning | ||
value: conf/provisioning | ||
|
||
- name: Start grafana again | ||
supervisorctl: | ||
name: grafana | ||
state: restarted | ||
|
||
- name: Wait for grafana initialization | ||
pause: | ||
seconds: 5 | ||
|
||
- name: Fix database/folder relationship | ||
command: grafana-db-migrator --fix-folders-id /srv/grafana/grafana.db "postgres://grafana:grafana@localhost:5432/grafana?sslmode=disable" | ||
register: migrator_output | ||
changed_when: "'All done' in migrator_output.stdout" | ||
|
||
- name: Remove SQLite Grafana database | ||
file: | ||
path: /srv/grafana/grafana.db | ||
state: absent |
This file contains 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