From 03b6a4d948c7158bbdfb1df589156bdcd8320acf Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Sat, 20 Feb 2021 09:25:27 +0100
Subject: [PATCH] Update mysql replication setup

---
 docs/ansible/roles/mysql/index.md | 45 ++++++++++++++++++++++++++++---
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git a/docs/ansible/roles/mysql/index.md b/docs/ansible/roles/mysql/index.md
index 402cc50..6fd8801 100644
--- a/docs/ansible/roles/mysql/index.md
+++ b/docs/ansible/roles/mysql/index.md
@@ -43,7 +43,7 @@ drupal_settings:
             - access*
 ```
 
-# Replcation
+# Replication
 
 - [Replication Configuration](https://dev.mysql.com/doc/refman/5.7/en/replication.html)
 - [Replication SQL Statements](https://dev.mysql.com/doc/refman/5.7/en/sql-replication-statements.html)
@@ -54,6 +54,43 @@ Starting from [here](https://dev.mysql.com/doc/refman/5.7/en/replication-howto-m
 
 - Create a DB dump: lock tables, remember bin log position, dump db (see [Choosing a Method for Data Snapshots](https://dev.mysql.com/doc/refman/5.7/en/replication-snapshot-method.html)) and copy to secondary host
 - Unlock the tables again
-- Configure secondary for new master with Ansible playbook `dans COMPANY mysqlsecondary --tags=changemaster --extra-vars="port=[PORT]" --extra-vars="binpos=[BINLOGPOS]"`
-- On the secondary, start the MySQL server and turn off replication (`stop slave`)
-- Import dump file and then start replication again (`start slave`)
+- Configure secondary for new master with Ansible playbook
+- On the secondary, start the MySQL server and turn off replication
+- Import dump file and then start replication again
+
+**On the primary:**
+
+```mysql
+FLUSH TABLES WITH READ LOCK;
+SHOW MASTER STATUS;
+```
+
+**On the primary in a second shell:**
+
+```shell
+mysqldump --all-databases --master-data > dbdump.db
+scp dbdump.db >[SECONDARY]:
+```
+
+**On the primary:**
+
+```mysql
+UNLOCK TABLES;
+```
+
+**With Ansible:**
+
+```shell
+apb mysqlsecondary --company=[COMPANY] --tags=changemaster --extra-vars="port=[PORT]" --extra-vars="binpos=[BINPOS]" --extra-vars="binlog=/var/log/mysql/[BINPOS]"
+```
+
+**On the secondary:**
+
+```shell
+mysql < dbdump.db
+```
+
+```mysql
+START SLAVE;
+SHOW SLAVE STATUS;
+```
-- 
GitLab