From 5da2adfce23569a709623f3f49f915e427363a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavi=20Lle=C3=B3=20Tom=C3=A1s?= Date: Fri, 31 Jan 2025 15:47:37 +0100 Subject: [PATCH] refs #8414 - Add new db section --- roles/services/files/mariabackupdev/apply.sql | 23 ++++++++ .../bacula-after.sh | 0 .../apply.sql | 0 .../files/mariabackuptest/bacula-after.sh | 51 +++++++++++++++++ roles/services/tasks/mariadb.yml | 57 ++++++++++++++++--- .../templates/test-db_dev/apply.config.sh | 4 +- 6 files changed, 125 insertions(+), 10 deletions(-) create mode 100644 roles/services/files/mariabackupdev/apply.sql rename roles/services/files/{mariabackuptest_dev => mariabackupdev}/bacula-after.sh (100%) rename roles/services/files/{mariabackuptest_dev => mariabackuptest}/apply.sql (100%) create mode 100755 roles/services/files/mariabackuptest/bacula-after.sh diff --git a/roles/services/files/mariabackupdev/apply.sql b/roles/services/files/mariabackupdev/apply.sql new file mode 100644 index 0000000..b6aab80 --- /dev/null +++ b/roles/services/files/mariabackupdev/apply.sql @@ -0,0 +1,23 @@ +UPDATE vn2008.tblContadores + SET dbproduccion = FALSE; + +DELETE FROM util.binlogQueue; + +GRANT + SELECT, + INSERT, + UPDATE, + DELETE, + CREATE, + DROP, + INDEX, + ALTER, + CREATE TEMPORARY TABLES, + CREATE VIEW, + EVENT, + TRIGGER, + SHOW VIEW, + CREATE ROUTINE, + ALTER ROUTINE, + EXECUTE + ON *.* TO developerBoss; diff --git a/roles/services/files/mariabackuptest_dev/bacula-after.sh b/roles/services/files/mariabackupdev/bacula-after.sh similarity index 100% rename from roles/services/files/mariabackuptest_dev/bacula-after.sh rename to roles/services/files/mariabackupdev/bacula-after.sh diff --git a/roles/services/files/mariabackuptest_dev/apply.sql b/roles/services/files/mariabackuptest/apply.sql similarity index 100% rename from roles/services/files/mariabackuptest_dev/apply.sql rename to roles/services/files/mariabackuptest/apply.sql diff --git a/roles/services/files/mariabackuptest/bacula-after.sh b/roles/services/files/mariabackuptest/bacula-after.sh new file mode 100755 index 0000000..53e37bb --- /dev/null +++ b/roles/services/files/mariabackuptest/bacula-after.sh @@ -0,0 +1,51 @@ +#!/bin/bash +set -e + +myDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +. "$myDir/config.sh" +. "$myDir/apply.config.sh" + +todayDir=$(date +%Y-%m-%d) +pattern="$baculaDir/mnt/local-backup/${todayDir}_??-??_full.gz" +files=($pattern) +backupFile="${files[0]}" + +"$myDir/restore-backup.sh" "$backupFile" +rm -r "$baculaDir" + +if [[ "${#dbClusterSiblings[@]}" -gt "0" ]]; then + for node in "${dbClusterSiblings[@]}"; do + ssh root@$node service mysql stop + ssh root@$node "if pgrep mariadbd; then pkill -9 mariadbd; fi" + done + + galera_new_cluster +else + service mariadb start +fi + +echo "Applying custom script." +mysql -e "UPDATE util.config SET environment = '$dbEnvironment', lastDump = NOW()" +mysql < "$myDir/apply.sql" + +echo "Upgrading tables." +mysql_upgrade + +echo "Applying repository changes." +curl --silent --request POST --location --user "$jenkinsAuth" "$jenkinsUrl/build?delay=0sec" + +echo "Waiting for Jenkins job to end." +jobResult=null +while [ "$jobResult" = "null" ]; do + sleep 10 + jobResult=$(curl --silent --location --user "$jenkinsAuth" "$jenkinsUrl/lastBuild/api/json" | jq --raw-output ".result") +done +echo "Job result: $jobResult" + +echo "Promoting to master." +"/root/scripts/promote-master.sh" + +for node in "${dbClusterSiblings[@]}"; do + ssh root@$node service mysql start +done + diff --git a/roles/services/tasks/mariadb.yml b/roles/services/tasks/mariadb.yml index 398d6b1..0ee6e98 100644 --- a/roles/services/tasks/mariadb.yml +++ b/roles/services/tasks/mariadb.yml @@ -81,7 +81,7 @@ loop: "{{ certificates }}" notify: restart-mariadb -- when: production is true +- when: db.branch == 'production' block: - name: Set MariaDB custom configuration Production copy: @@ -104,10 +104,10 @@ - /mnt/local-backup Make sure they are correctly configured and accessible. -- when: production is false or production is not defined +- when: db.branch == 'test' block: - - name: Set MariaDB custom configuration Test-DB-DEV + - name: Set MariaDB custom configuration TestDB copy: src: "{{ item }}" dest: /etc/mysql/mariadb.conf.d/ @@ -119,7 +119,7 @@ - "files/mariaconfigfiles/z92-testing_dev.cnf" notify: restart-mariadb - - name: Set MariaBackup custom template configuration Test-DB-DEV + - name: Set MariaBackup custom template configuration TestDB template: src: test-db_dev/apply.config.sh dest: /root/mariabackup/ @@ -127,7 +127,7 @@ group: root mode: u=rw,g=,o= - - name: Set MariaDB local configuration file for Test-DB-DEV + - name: Set MariaDB local configuration file for TestDB copy: src: "{{ item }}" dest: /root/mariabackup/ @@ -135,10 +135,51 @@ group: root mode: u=rw,g=r,o=r with_items: - - "mariabackuptest_dev/apply.sql" - - "mariabackuptest_dev/bacula-after.sh" + - "mariabackuptest/apply.sql" + - "mariabackuptest/bacula-after.sh" - - name: Reminder to check mount points environment Test-DB-DEV + - name: Reminder to check mount points environment TestDB + debug: + msg: | + Remember to check the following mount points: + - /mnt/mysqltmp + Make sure they are correctly configured and accessible. + +- when: db.branch == 'dev' + + block: + - name: Set MariaDB custom configuration DevDB + copy: + src: "{{ item }}" + dest: /etc/mysql/mariadb.conf.d/ + owner: root + group: root + mode: u=rw,g=r,o=r + with_items: + - "files/mariaconfigfiles/z90-vn.cnf" + - "files/mariaconfigfiles/z92-testing_dev.cnf" + notify: restart-mariadb + + - name: Set MariaBackup custom template configuration DevDB + template: + src: test-db_dev/apply.config.sh + dest: /root/mariabackup/ + owner: root + group: root + mode: u=rw,g=,o= + + - name: Set MariaDB local configuration file for DevDB + copy: + src: "{{ item }}" + dest: /root/mariabackup/ + owner: root + group: root + mode: u=rw,g=r,o=r + with_items: + - "mariabackupdev/apply.sql" + - "mariabackupdev/bacula-after.sh" + + - name: Reminder to check mount points environment DevDB debug: msg: | Remember to check the following mount points: diff --git a/roles/services/templates/test-db_dev/apply.config.sh b/roles/services/templates/test-db_dev/apply.config.sh index 6894c3f..8d15118 100755 --- a/roles/services/templates/test-db_dev/apply.config.sh +++ b/roles/services/templates/test-db_dev/apply.config.sh @@ -4,7 +4,7 @@ baculaDir=/mnt/mysqldata/bacula-restore # Database branch name -dbBranch={{ dbBranch }} +dbBranch={{ db.branch }} # Database environment dbEnvironment={{ dbEnvironment }} @@ -16,5 +16,5 @@ dbClusterSiblings=() jenkinsAuth=jenkins:{{ lookup(passbolt, 'jenkinsAuth', folder_parent_id=passbolt_folder).password }} # Jenkins job URL -jenkinsUrl=https://jenkins.verdnatura.es/job/Scheduler/job/db-apply-changes-{{ dbBranch }} +jenkinsUrl=https://jenkins.verdnatura.es/job/Scheduler/job/db-apply-changes-{{ db.branch }}