summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@vps-18a7a2b7.vps.ovh.ca>2023-06-08 18:06:48 -0400
committerroot <root@vps-18a7a2b7.vps.ovh.ca>2023-06-08 18:06:48 -0400
commit517d8a6c3bffcb2fe8f37551b2826b7391c4a823 (patch)
treec4f13095980babfda7fe69be66fb148fbde7628d
parentcadd6e41b9c055d31e5ef088ad351ca302b10159 (diff)
committing old WIP
-rwxr-xr-xmariadb-push-replica.sh44
1 files changed, 44 insertions, 0 deletions
diff --git a/mariadb-push-replica.sh b/mariadb-push-replica.sh
new file mode 100755
index 0000000..d645c91
--- /dev/null
+++ b/mariadb-push-replica.sh
@@ -0,0 +1,44 @@
1#!/bin/bash
2set -ex
3
4default_slave_remote_file=data/default-slave-remote
5master_password_file=data/mysql-master-password
6
7if [ -r "$default_slave_remote_file" ]
8then
9 read default_remote_host < "$default_slave_remote_file"
10fi
11
12gen_password()
13{
14 generated_password_length=32
15 generated_password=$(tr -cd a-zA-Z0-9 < /dev/urandom | head -c "$generated_password_length")
16 [ "${#generated_password}" -eq "$generated_password_length" ]
17 printf '%s\n' "$generated_password"
18}
19
20if ! [ -e "$master_password_file" ]
21then
22 gen_password > "$master_password_file"
23fi
24
25if [ -r "$master_password_file" ]
26then
27 read master_password < "$master_password_file"
28 [ "${#master_password}" -ge 30 ]
29fi
30
31our_host=$(hostname --fqdn)
32remote_host=${1:-$default_remote_host}
33
34[ "$our_host" ]
35[ "$remote_host" ]
36
37master_password=$(false)
38
39ssh -l root "$remote_host" -- mariadb <<END
40CHANGE MASTER TO
41 MASTER_HOST='$our_host',
42 MASTER_USER='replication',
43 MASTER_PASSWORD='$master_password'
44END