diff options
author | root <root@vps-18a7a2b7.vps.ovh.ca> | 2024-01-14 23:50:50 -0500 |
---|---|---|
committer | root <root@vps-18a7a2b7.vps.ovh.ca> | 2024-01-14 23:50:50 -0500 |
commit | 306f3977f5c0addc8fb0af231d54bf14bde6f639 (patch) | |
tree | 03d308a24ae759a407fad5fe3ad7ebb4a0021442 | |
parent | 17e91005ccedc355cb213fda0cbbe674a847ea85 (diff) |
old wip
-rwxr-xr-x | wip/mariadb-push-replica.sh | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/wip/mariadb-push-replica.sh b/wip/mariadb-push-replica.sh new file mode 100755 index 0000000..fbf9402 --- /dev/null +++ b/wip/mariadb-push-replica.sh | |||
@@ -0,0 +1,80 @@ | |||
1 | #!/bin/bash | ||
2 | set -ex | ||
3 | |||
4 | default_slave_remote_file=data/default-slave-remote | ||
5 | master_password_file=data/mysql-master-password | ||
6 | |||
7 | if [ -r "$default_slave_remote_file" ] | ||
8 | then | ||
9 | read default_remote_host < "$default_slave_remote_file" | ||
10 | fi | ||
11 | |||
12 | gen_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 | |||
20 | if ! [ -e "$master_password_file" ] | ||
21 | then | ||
22 | gen_password > "$master_password_file" | ||
23 | fi | ||
24 | |||
25 | if [ -r "$master_password_file" ] | ||
26 | then | ||
27 | read master_password < "$master_password_file" | ||
28 | [ "${#master_password}" -ge 30 ] | ||
29 | fi | ||
30 | |||
31 | our_host=$(hostname --fqdn) | ||
32 | remote_host=${1:-$default_remote_host} | ||
33 | |||
34 | rpc_funcs= | ||
35 | |||
36 | rpc() | ||
37 | { | ||
38 | read shellscript < <(declare -f $rpc_funcs; echo $*) | ||
39 | set -- $shellscript | ||
40 | ssh -l "$remote_user" -- "$remote_host" ${*@Q} | ||
41 | } | ||
42 | |||
43 | [ "$our_host" ] | ||
44 | [ "$remote_host" ] | ||
45 | [ "$master_password" ] | ||
46 | |||
47 | primarydb_create_user() | ||
48 | { | ||
49 | : | ||
50 | } | ||
51 | |||
52 | mariabackup_target_dir=/var/mariadb/backup | ||
53 | primarydb_export_backup() | ||
54 | { | ||
55 | mkdir -p "$mariabackup_target_dir" | ||
56 | mariabackup --backup --target-dir="$mariabackup_target_dir" | ||
57 | } | ||
58 | |||
59 | primarydb() | ||
60 | { | ||
61 | ssh -l root "$remote_host" -- "$@" | ||
62 | } | ||
63 | remote_user=root | ||
64 | rpc uptime | ||
65 | exit 1 | ||
66 | |||
67 | ssh -l root "$remote_host" -- mariadb -t <<END | ||
68 | select @@hostname, @@server_id, @@gtid_slave_pos, @@sql_log_bin; | ||
69 | SELECT VARIABLE_NAME,SESSION_VALUE,GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME='sql_log_bin' OR VARIABLE_NAME='HOSTNAME' \G | ||
70 | SELECT VARIABLE_NAME,SESSION_VALUE,GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES \G | ||
71 | END | ||
72 | |||
73 | exit 0 | ||
74 | |||
75 | ssh -l root "$remote_host" -- mariadb <<END | ||
76 | CHANGE MASTER TO | ||
77 | MASTER_HOST='$our_host', | ||
78 | MASTER_USER='replication', | ||
79 | MASTER_PASSWORD='$master_password' | ||
80 | END | ||