Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 2.27 KB

File metadata and controls

71 lines (49 loc) · 2.27 KB

Reset MariaDB Replication for your Code Dx database

Here are the steps that use four terminal windows to reset MariaDB database replication (when not using an external database):

Note: The steps assume two statefulsets named codedx-mariadb-master and codedx-mariadb-slave and a deployment named codedx in the cdx-app namespace with one subordinate database.

Terminal 1 (Subordinate DB):

  1. kubectl -n cdx-app scale --replicas=0 deployment/codedx
  2. kubectl -n cdx-app exec -it codedx-mariadb-slave-0 -- bash
  3. mysql -uroot -p
  4. STOP SLAVE;
  5. exit # mysql

Terminal 2 (Master DB):

  1. kubectl -n cdx-app exec -it codedx-mariadb-master-0 -- bash
  2. mysql -uroot -p
  3. RESET MASTER;

Note: RESET MASTER deletes previous binary log files, creating a new binary log file.

  1. FLUSH TABLES WITH READ LOCK;

Terminal 3 (Master DB):

  1. kubectl -n cdx-app exec -it codedx-mariadb-master-0 -- bash
  2. mysqldump -u root -p codedx > /bitnami/mariadb/codedx-dump.sql

Note: The above command assumes you have adequate space at /bitnami/mariadb to store your database backup. Use an alternate path as necessary, and adjust paths in subsequent steps accordingly.

Terminal 2 (Master DB)

  1. UNLOCK TABLES;

Terminal 4:

  1. kubectl -n cdx-app cp codedx-mariadb-master-0:/bitnami/mariadb/codedx-dump.sql ./codedx-dump.sql
  2. kubectl -n cdx-app cp ./codedx-dump.sql codedx-mariadb-slave-0:/bitnami/mariadb/codedx-dump.sql

Terminal 1 (Subordinate DB):

  1. mysql -u root -p codedx < /bitnami/mariadb/codedx-dump.sql
  2. mysql -uroot -p
  3. RESET SLAVE;

Note: RESET SLAVE deletes relay log files.

  1. Remove old binary log files by running "SHOW BINARY LOGS;" and "PURGE BINARY LOGS TO 'name';"

Note: If you previously deleted binary log files (mysql-bin.000*) from the file system, remove the contents of the mysql-bin.index text file.

  1. CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=1;
  2. START SLAVE;
  3. SHOW SLAVE STATUS \G;
  4. exit # mysql
  5. rm /bitnami/mariadb/codedx-dump.sql
  6. exit # pod
  7. exit # terminal

Terminal 2 (Master DB):

  1. exit # mysql
  2. rm /bitnami/mariadb/codedx-dump.sql
  3. exit # pod
  4. exit # terminal

Terminal 3 (Master DB):

  1. exit # pod
  2. exit # terminal

Terminal 4:

  1. kubectl -n cdx-app scale --replicas=1 deployment/codedx
  2. exit # terminal